Skip to content

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

test_checkout_remove_shipping_method (#14252)

Renata23597a794e3e
diff --git a/saleor/tests/e2e/checkout/test_checkout_should_be_able_to_remove_shipping_method.py b/saleor/tests/e2e/checkout/test_checkout_should_be_able_to_remove_shipping_method.py
new file mode 100644
index 0000000000..cc7e6fbb5b
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_checkout_should_be_able_to_remove_shipping_method.py
@@ -0,0 +1,96 @@
+import pytest
+
+from ..product.utils.preparing_product import prepare_product
+from ..shop.utils.preparing_shop import prepare_shop
+from ..utils import assign_permissions
+from .utils import checkout_create, checkout_delivery_method_update
+
+
+def test_checkout_should_be_able_to_remove_shipping_method_CORE_0115(
+ e2e_staff_api_client,
+ e2e_not_logged_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_product_types_and_attributes,
+ permission_manage_shipping,
+ permission_manage_orders,
+ permission_manage_checkouts,
+):
+ # Before
+ permissions = [
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+ permission_manage_checkouts,
+ ]
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ (
+ warehouse_id,
+ channel_id,
+ channel_slug,
+ shipping_method_id,
+ ) = prepare_shop(e2e_staff_api_client)
+
+ variant_price = 10
+
+ (
+ _product_id,
+ product_variant_id,
+ _product_variant_price,
+ ) = prepare_product(
+ e2e_staff_api_client,
+ warehouse_id,
+ channel_id,
+ variant_price,
+ )
+
+ # Step 1 - Create checkout
+ lines = [
+ {
+ "variantId": product_variant_id,
+ "quantity": 1,
+ },
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+ assert checkout_data["shippingMethods"] != []
+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]
+ assert checkout_data["isShippingRequired"] is True
+ assert checkout_data["deliveryMethod"] is None
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+ assert total_gross_amount == variant_price
+
+ # Step 2 - Set DeliveryMethod for checkout
+ checkout_data = checkout_delivery_method_update(
+ e2e_not_logged_api_client,
+ checkout_id,
+ shipping_method_id,
+ )
+ subtotal_price = checkout_data["subtotalPrice"]["gross"]["amount"]
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+ shipping_price = checkout_data["deliveryMethod"]["price"]["amount"]
+ assert subtotal_price == float(variant_price)
+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id
+ assert total_gross_amount == float(subtotal_price + shipping_price)
+
+ # Step 3 - Remove shipping method from the checkout
+ checkout_data = checkout_delivery_method_update(
+ e2e_not_logged_api_client,
+ checkout_id,
+ )
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+ shipping_price = checkout_data["shippingPrice"]["gross"]["amount"]
+ assert shipping_price == 0
+ assert total_gross_amount == float(variant_price)
+ assert checkout_data["deliveryMethod"] is None
diff --git a/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py b/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py
index b57c08d110..6b66367bb8 100644
--- a/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py
+++ b/saleor/tests/e2e/checkout/utils/checkout_delivery_method_update.py
@@ -1,7 +1,7 @@
from ...utils import get_graphql_content
CHECKOUT_DELIVERY_METHOD_UPDATE_MUTATION = """
-mutation checkoutDeliveryMethodUpdate($checkoutId: ID!, $deliveryMethodId: ID!) {
+mutation checkoutDeliveryMethodUpdate($checkoutId: ID!, $deliveryMethodId: ID) {
checkoutDeliveryMethodUpdate(
id: $checkoutId
deliveryMethodId: $deliveryMethodId
@@ -23,6 +23,11 @@ mutation checkoutDeliveryMethodUpdate($checkoutId: ID!, $deliveryMethodId: ID!)
amount
}
}
+ shippingPrice{
+ gross {
+ amount
+ }
+ }
shippingMethods {
id
}
@@ -46,7 +51,7 @@ mutation checkoutDeliveryMethodUpdate($checkoutId: ID!, $deliveryMethodId: ID!)
def checkout_delivery_method_update(
staff_api_client,
checkout_id,
- delivery_method_id,
+ delivery_method_id=None,
):
variables = {
"checkoutId": checkout_id,