Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add test for check remove shipping for specific checkout

fowczarek2312804e3521
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 5534258401..f0e65e9b26 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -340,7 +340,7 @@ class CheckoutLinesAdd(BaseMutation):
quantities = [line.get("quantity") for line in lines]
check_lines_quantity(variants, quantities)
- update_checkout_shipping_method_if_invalid(checkout, info.context.discounts)
+ # update_checkout_shipping_method_if_invalid(checkout, info.context.discounts)
if variants and quantities:
for variant, quantity in zip(variants, quantities):
@@ -353,6 +353,7 @@ class CheckoutLinesAdd(BaseMutation):
f"Insufficient product stock: {exc.item}", code=exc.code
)
+ update_checkout_shipping_method_if_invalid(checkout, info.context.discounts)
recalculate_checkout_discount(checkout, info.context.discounts)
return CheckoutLinesAdd(checkout=checkout)
diff --git a/tests/api/test_checkout_digital.py b/tests/api/test_checkout_digital.py
index a58d44840c..5603ac9c8f 100644
--- a/tests/api/test_checkout_digital.py
+++ b/tests/api/test_checkout_digital.py
@@ -1,22 +1,22 @@
"""Test the API's checkout process over full digital orders."""
-import pytest
import graphene
+import pytest
from saleor.account.models import Address
from saleor.checkout import calculations
from saleor.checkout.error_codes import CheckoutErrorCode
from saleor.checkout.models import Checkout
from saleor.checkout.utils import add_variant_to_checkout
+from saleor.graphql.checkout.mutations import update_checkout_shipping_method_if_invalid
from saleor.order.models import Order
from tests.api.utils import get_graphql_content
-from saleor.graphql.checkout.mutations import update_checkout_shipping_method_if_invalid
from .test_checkout import (
MUTATION_CHECKOUT_COMPLETE,
MUTATION_CHECKOUT_CREATE,
+ MUTATION_CHECKOUT_LINES_UPDATE,
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE,
MUTATION_UPDATE_SHIPPING_METHOD,
- MUTATION_CHECKOUT_LINES_UPDATE,
)
@@ -202,7 +202,6 @@ def test_checkout_complete(
def test_remove_shipping_method_if_only_digital_in_checkout(
checkout_with_digital_item, address, shipping_method
):
-
checkout = checkout_with_digital_item
checkout.shipping_address = address
checkout.shipping_method = shipping_method
@@ -213,3 +212,32 @@ def test_remove_shipping_method_if_only_digital_in_checkout(
checkout.refresh_from_db()
assert not checkout.shipping_method
+
+
+def test_checkout_lines_update_remove_shipping_if_removed_product_with_shipping(
+ user_api_client, checkout_with_item, digital_content, address, shipping_method
+):
+ checkout = checkout_with_item
+ digital_variant = digital_content.product_variant
+ checkout.shipping_address = address
+ checkout.shipping_method = shipping_method
+ checkout.save()
+ add_variant_to_checkout(checkout, digital_variant, 1)
+ line = checkout.lines.first()
+ variant = line.variant
+
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.pk)
+ checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
+
+ variables = {
+ "checkoutId": checkout_id,
+ "lines": [{"variantId": variant_id, "quantity": 0}],
+ }
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_UPDATE, variables)
+ content = get_graphql_content(response)
+
+ data = content["data"]["checkoutLinesUpdate"]
+ assert not data["errors"]
+ checkout.refresh_from_db()
+ assert checkout.lines.count() == 1
+ assert not checkout.shipping_method