Skip to content

Commit

Permalink
Fix CheckoutInfoByCheckoutTokenLoader for checkout with voucher that …
Browse files Browse the repository at this point in the history
…does not exist
  • Loading branch information
IKarbowiak committed May 2, 2024
1 parent cbd1dad commit c1fa702
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions saleor/graphql/checkout/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ def with_checkout_info(results):
voucher_code_map = {
voucher_code.code: voucher_code
for voucher_code in voucher_codes
if voucher_code
}
tax_configuration_by_channel_map = {
tax_configuration.channel_id: tax_configuration
Expand Down
65 changes: 65 additions & 0 deletions saleor/graphql/checkout/tests/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,71 @@ def test_checkout_prices_with_voucher(user_api_client, checkout_with_item_and_vo
)


def test_checkout_prices_with_voucher_code_that_doesnt_exist(
user_api_client, checkout_with_item_and_voucher, voucher
):
# given
checkout = checkout_with_item_and_voucher
query = QUERY_CHECKOUT_PRICES
variables = {"id": to_global_id_or_none(checkout)}
voucher.delete()

# when
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"]["checkout"]

# then
assert data["token"] == str(checkout.token)
assert len(data["lines"]) == checkout.lines.count()
manager = get_plugins_manager(allow_replica=False)
lines, _ = fetch_checkout_lines(checkout)
checkout_info = fetch_checkout_info(checkout, lines, manager)
total = calculations.checkout_total(
manager=manager,
checkout_info=checkout_info,
lines=lines,
address=checkout_info.shipping_address,
)
assert data["totalPrice"]["gross"]["amount"] == (total.gross.amount)
subtotal = calculations.checkout_subtotal(
manager=manager,
checkout_info=checkout_info,
lines=lines,
address=checkout_info.shipping_address,
)
assert data["subtotalPrice"]["gross"]["amount"] == (subtotal.gross.amount)
line_info = lines[0]
assert line_info.line.quantity > 0
line_total_price = calculations.checkout_line_total(
manager=manager,
checkout_info=checkout_info,
lines=lines,
checkout_line_info=line_info,
)
assert data["lines"][0]["unitPrice"]["gross"]["amount"] == float(
quantize_price(
line_total_price.gross.amount / line_info.line.quantity, checkout.currency
)
)
assert (
data["lines"][0]["totalPrice"]["gross"]["amount"]
== line_total_price.gross.amount
)
undiscounted_unit_price = line_info.variant.get_price(
line_info.channel_listing,
line_info.line.price_override,
)
assert (
data["lines"][0]["undiscountedUnitPrice"]["amount"]
== undiscounted_unit_price.amount
)
assert (
data["lines"][0]["undiscountedTotalPrice"]["amount"]
== undiscounted_unit_price.amount * line_info.line.quantity
)


def test_query_checkouts(
checkout_with_item, staff_api_client, permission_manage_checkouts
):
Expand Down

0 comments on commit c1fa702

Please sign in to comment.