Skip to content

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

[TEST] Adding a test for checkout with creating order without payment CORE_0111 (#13576)

Renata0b9aa6534c7b
diff --git a/saleor/tests/e2e/channel/utils.py b/saleor/tests/e2e/channel/utils.py
index acfbaa6cdf..4190a24f0b 100644
--- a/saleor/tests/e2e/channel/utils.py
+++ b/saleor/tests/e2e/channel/utils.py
@@ -34,6 +34,9 @@ def create_channel(
currency="USD",
country="US",
is_active=True,
+ automatically_fulfill_non_shippable_giftcard=False,
+ allow_unpaid_orders=False,
+ automatically_confirm_all_new_orders=True,
):
if not warehouse_ids:
warehouse_ids = []
@@ -46,6 +49,15 @@ def create_channel(
"defaultCountry": country,
"isActive": is_active,
"addWarehouses": warehouse_ids,
+ "orderSettings": {
+ "automaticallyFulfillNonShippableGiftCard": (
+ automatically_fulfill_non_shippable_giftcard
+ ),
+ "allowUnpaidOrders": allow_unpaid_orders,
+ "automaticallyConfirmAllNewOrders": (
+ automatically_confirm_all_new_orders
+ ),
+ },
}
}
diff --git a/saleor/tests/e2e/checkout/test_checkout_create_order_with_no_payment.py b/saleor/tests/e2e/checkout/test_checkout_create_order_with_no_payment.py
new file mode 100644
index 0000000000..7a9e5082a4
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_checkout_create_order_with_no_payment.py
@@ -0,0 +1,163 @@
+import pytest
+
+from ..channel.utils import create_channel
+from ..product.utils import (
+ create_category,
+ create_product,
+ create_product_channel_listing,
+ create_product_type,
+ create_product_variant,
+ create_product_variant_channel_listing,
+)
+from ..shipping_zone.utils import (
+ create_shipping_method,
+ create_shipping_method_channel_listing,
+ create_shipping_zone,
+)
+from ..utils import assign_permissions
+from ..warehouse.utils import create_warehouse
+from .utils import (
+ checkout_create,
+ checkout_delivery_method_update,
+ raw_checkout_complete,
+)
+
+
+def prepare_product(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+ channel_slug,
+):
+ permissions = [
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+ ]
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ warehouse_data = create_warehouse(e2e_staff_api_client)
+ warehouse_id = warehouse_data["id"]
+
+ warehouse_ids = [warehouse_id]
+ channel_data = create_channel(
+ e2e_staff_api_client,
+ slug=channel_slug,
+ warehouse_ids=warehouse_ids,
+ allow_unpaid_orders=True,
+ automatically_confirm_all_new_orders=True,
+ )
+ channel_id = channel_data["id"]
+
+ channel_ids = [channel_id]
+ shipping_zone_data = create_shipping_zone(
+ e2e_staff_api_client,
+ warehouse_ids=warehouse_ids,
+ channel_ids=channel_ids,
+ )
+ shipping_zone_id = shipping_zone_data["id"]
+
+ shipping_method_data = create_shipping_method(
+ e2e_staff_api_client, shipping_zone_id
+ )
+ shipping_method_id = shipping_method_data["id"]
+
+ create_shipping_method_channel_listing(
+ e2e_staff_api_client, shipping_method_id, channel_id
+ )
+
+ product_type_data = create_product_type(
+ e2e_staff_api_client,
+ )
+ product_type_id = product_type_data["id"]
+
+ category_data = create_category(e2e_staff_api_client)
+ category_id = category_data["id"]
+
+ product_data = create_product(e2e_staff_api_client, product_type_id, category_id)
+ product_id = product_data["id"]
+
+ create_product_channel_listing(e2e_staff_api_client, product_id, channel_id)
+
+ stocks = [
+ {
+ "warehouse": warehouse_id,
+ "quantity": 5,
+ }
+ ]
+ product_variant_data = create_product_variant(
+ e2e_staff_api_client,
+ product_id,
+ stocks=stocks,
+ )
+ product_variant_id = product_variant_data["id"]
+
+ create_product_variant_channel_listing(
+ e2e_staff_api_client,
+ product_variant_id,
+ channel_id,
+ )
+
+ return product_variant_id
+
+
+def test_should_be_able_to_create_order_with_no_payment(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+):
+ # Before
+ channel_slug = "test-channel"
+ product_variant_id = prepare_product(
+ e2e_staff_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+ channel_slug,
+ )
+
+ # Step 1 - Create checkout.
+ lines = [
+ {"variantId": product_variant_id, "quantity": 1},
+ ]
+ checkout_data = checkout_create(
+ e2e_staff_api_client,
+ lines,
+ channel_slug,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+
+ assert checkout_data["isShippingRequired"] is True
+ assert checkout_data["deliveryMethod"] is None
+ assert checkout_data["shippingMethod"] is None
+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]
+
+ # Step 2 - Set shipping address and DeliveryMethod for checkout
+ checkout_data = checkout_delivery_method_update(
+ e2e_staff_api_client,
+ checkout_id,
+ shipping_method_id,
+ )
+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id
+
+ # Step 3 - Checkout complete results in the order creation
+ data = raw_checkout_complete(e2e_staff_api_client, checkout_id)
+ order_data = data["order"]
+ assert order_data["id"] is not None
+ assert order_data["isShippingRequired"] is True
+ assert order_data["paymentStatus"] == "NOT_CHARGED"
+ assert order_data["status"] == "UNCONFIRMED"
+ assert order_data["isPaid"] is False
+
+ errors = data["errors"]
+ assert errors == []
diff --git a/saleor/tests/e2e/checkout/utils/checkout_complete.py b/saleor/tests/e2e/checkout/utils/checkout_complete.py
index 6a094e1854..fa97379eee 100644
--- a/saleor/tests/e2e/checkout/utils/checkout_complete.py
+++ b/saleor/tests/e2e/checkout/utils/checkout_complete.py
@@ -20,6 +20,10 @@ mutation CheckoutComplete($checkoutId: ID!) {
amount
}
}
+ paymentStatus
+ statusDisplay
+ status
+ isPaid
checkoutId
deliveryMethod {
... on ShippingMethod {