Skip to content

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

Add test for checkout with different shipping zones

Michał Sipa7c3abd384d54
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.py
index d330329c19..fb8c13e410 100644
--- a/saleor/graphql/checkout/tests/test_checkout.py
+++ b/saleor/graphql/checkout/tests/test_checkout.py
@@ -527,6 +527,34 @@ def test_checkout_create_check_lines_quantity_multiple_warehouse(
assert data["errors"][0]["field"] == "quantity"
+def test_checkout_create_check_lines_quantity_from_shipping_address_country(
+ user_api_client,
+ variant_with_many_stocks_different_shipping_zones,
+ graphql_address_data,
+):
+ variant = variant_with_many_stocks_different_shipping_zones
+ variant_id = graphene.Node.to_global_id("ProductVariant", variant.id)
+ test_email = "[email protected]"
+ shipping_address = graphql_address_data
+ shipping_address["country"] = "US"
+ shipping_address["countryArea"] = "New York"
+ shipping_address["postalCode"] = 10001
+ variables = {
+ "checkoutInput": {
+ "lines": [{"quantity": 1, "variantId": variant_id}],
+ "email": test_email,
+ "shippingAddress": shipping_address,
+ }
+ }
+ assert not Checkout.objects.exists()
+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_CREATE, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["checkoutCreate"]
+ assert data["created"] == True
+ checkout = Checkout.objects.first()
+ assert checkout.country == "US"
+
+
def test_checkout_create_check_lines_quantity(
user_api_client, stock, graphql_address_data
):
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
index 1cf9ffd215..7871780be7 100644
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -495,6 +495,27 @@ def shipping_zone(db): # pylint: disable=W0613
return shipping_zone
+def shipping_zones(db):
+ shipping_zone_poland = ShippingZone.objects.create(name="Poland", countries=["PL"])
+ shipping_zone_poland.shipping_methods.create(
+ name="DHL",
+ minimum_order_price=Money(0, "USD"),
+ type=ShippingMethodType.PRICE_BASED,
+ price=Money(10, "USD"),
+ shipping_zone=shipping_zone,
+ )
+ shipping_zone_usa = ShippingZone.objects.create(name="USA", countries=["USA"])
+ shipping_zone_usa.shipping_methods.create(
+ name="DHL",
+ minimum_order_price=Money(0, "USD"),
+ type=ShippingMethodType.PRICE_BASED,
+ price=Money(10, "USD"),
+ shipping_zone=shipping_zone,
+ )
+ return [shipping_zone_poland, shipping_zone_usa]
+
+
@pytest.fixture
def shipping_zone_without_countries(db): # pylint: disable=W0613
shipping_zone = ShippingZone.objects.create(name="Europe", countries=[])
@@ -859,6 +880,16 @@ def variant_with_many_stocks(variant, warehouses_with_shipping_zone):
return variant
+def variant_with_many_stocks_different_shipping_zones(
+ variant, warehouses_with_different_shipping_zone
+):
+ warehouses = warehouses_with_different_shipping_zone
+ Stock.objects.create(warehouse=warehouses[0], product_variant=variant, quantity=4)
+ Stock.objects.create(warehouse=warehouses[1], product_variant=variant, quantity=3)
+ return variant
+
+
@pytest.fixture
def product_variant_list(product):
return list(
@@ -2095,6 +2126,13 @@ def warehouses_with_shipping_zone(warehouses, shipping_zone):
return warehouses
+def warehouses_with_different_shipping_zone(warehouses, shipping_zone):
+ warehouses[0].shipping_zones.add(shipping_zone)
+ warehouses[1].shipping_zones.add(shipping_zone)
+ return warehouses
+
+
@pytest.fixture
def warehouse_no_shipping_zone(address):
warehouse = Warehouse.objects.create(