Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
test_unable_to_void_order_without_payment_CORE_0210 (#14234)
Renata2e261eae7396
diff --git a/saleor/tests/e2e/orders/test_unable_to_void_order_without_payment.py b/saleor/tests/e2e/orders/test_unable_to_void_order_without_payment.pynew file mode 100644index 0000000000..d126dd54bf--- /dev/null+++ b/saleor/tests/e2e/orders/test_unable_to_void_order_without_payment.py@@ -0,0 +1,110 @@+import pytest++from .. import DEFAULT_ADDRESS+from ..product.utils.preparing_product import prepare_product+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assign_permissions+from .utils import (+ draft_order_complete,+ draft_order_create,+ draft_order_update,+ order_lines_create,+ raw_order_void,+)+++def test_unable_to_void_order_without_payment_CORE_0210(+ e2e_staff_api_client,+ permission_manage_products,+ permission_manage_channels,+ permission_manage_product_types_and_attributes,+ permission_manage_shipping,+ permission_manage_orders,+):+ # Before+ permissions = [+ permission_manage_products,+ permission_manage_channels,+ permission_manage_shipping,+ permission_manage_product_types_and_attributes,+ permission_manage_orders,+ ]+ assign_permissions(e2e_staff_api_client, permissions)++ price = 10++ (+ warehouse_id,+ channel_id,+ _channel_slug,+ shipping_method_id,+ ) = prepare_shop(e2e_staff_api_client)++ (+ _product_id,+ product_variant_id,+ _product_variant_price,+ ) = prepare_product(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ price,+ )++ # Step 1 - Create draft order+ draft_order_input = {+ "channelId": channel_id,+ "userEmail": "[email protected]",+ "shippingAddress": DEFAULT_ADDRESS,+ "billingAddress": DEFAULT_ADDRESS,+ }+ data = draft_order_create(+ e2e_staff_api_client,+ draft_order_input,+ )+ order_id = data["order"]["id"]+ assert order_id is not None++ # Step 2 - Add lines to the order+ lines = [+ {+ "variantId": product_variant_id,+ "quantity": 1,+ }+ ]+ order_lines = order_lines_create(+ e2e_staff_api_client,+ order_id,+ lines,+ )+ order_product_variant_id = order_lines["order"]["lines"][0]["variant"]["id"]+ assert order_product_variant_id == product_variant_id++ # Step 3 - Update order's shipping method+ input = {"shippingMethod": shipping_method_id}+ draft_order = draft_order_update(+ e2e_staff_api_client,+ order_id,+ input,+ )+ order_shipping_id = draft_order["order"]["deliveryMethod"]["id"]+ assert order_shipping_id is not None++ # Step 4 - Complete the order+ order = draft_order_complete(e2e_staff_api_client, order_id)+ order_complete_id = order["order"]["id"]+ order_line = order["order"]["lines"][0]+ assert order_complete_id == order_id+ assert order_line["productVariantId"] == product_variant_id+ assert order["order"]["status"] == "UNFULFILLED"++ # Step 5 - Void the order+ order = raw_order_void(+ e2e_staff_api_client,+ order_id,+ )+ error = order["errors"][0]+ assert error["message"] == "There's no payment associated with the order."+ assert error["code"] == "PAYMENT_MISSING"+ assert error["field"] == "payment"diff --git a/saleor/tests/e2e/orders/utils/__init__.py b/saleor/tests/e2e/orders/utils/__init__.pyindex dbac47e428..4d0bc647f4 100644--- a/saleor/tests/e2e/orders/utils/__init__.py+++ b/saleor/tests/e2e/orders/utils/__init__.py@@ -8,6 +8,7 @@ from .order_discount_add import order_discount_addfrom .order_lines_create import order_lines_createfrom .order_mark_as_paid import mark_order_paidfrom .order_query import order_query+from .order_void import order_void, raw_order_void__all__ = ["raw_draft_order_complete",@@ -21,4 +22,6 @@ __all__ = ["draft_order_delete","order_create_from_checkout","order_discount_add",+ "raw_order_void",+ "order_void",]diff --git a/saleor/tests/e2e/orders/utils/order_void.py b/saleor/tests/e2e/orders/utils/order_void.pynew file mode 100644index 0000000000..c2fb9fe50d--- /dev/null+++ b/saleor/tests/e2e/orders/utils/order_void.py@@ -0,0 +1,49 @@+from ...utils import get_graphql_content++ORDER_VOID_MUTATION = """+mutation VoidOrder ($id:ID!){+ orderVoid(id: $id) {+ errors {+ code+ field+ message+ }+ order {+ id+ status+ }+ }+}+"""+++def raw_order_void(+ staff_api_client,+ order_id,+):+ variables = {+ "id": order_id,+ }+ raw_response = staff_api_client.post_graphql(+ ORDER_VOID_MUTATION,+ variables=variables,+ )+ content = get_graphql_content(raw_response)++ raw_data = content["data"]["orderVoid"]++ return raw_data+++def order_void(+ staff_api_client,+ order_id,+):+ response = raw_order_void(+ staff_api_client,+ order_id,+ )++ assert response["errors"] == []++ return response["orderVoid"]