Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
[Test] Should be able to buy gift card in the checkout (#14009)
Anna Szczęchfc718a08b7f4
diff --git a/saleor/tests/e2e/account/utils/__init__.py b/saleor/tests/e2e/account/utils/__init__.pyindex e78882a5b5..372309bfd2 100644--- a/saleor/tests/e2e/account/utils/__init__.py+++ b/saleor/tests/e2e/account/utils/__init__.py@@ -1,7 +1,9 @@from .account_register import account_register+from .me import get_own_datafrom .token_create import token_create__all__ = ["account_register","token_create",+ "get_own_data",]diff --git a/saleor/tests/e2e/account/utils/me.py b/saleor/tests/e2e/account/utils/me.pynew file mode 100644index 0000000000..5e8e4769c3--- /dev/null+++ b/saleor/tests/e2e/account/utils/me.py@@ -0,0 +1,31 @@+from ...utils import get_graphql_content++ME_QUERY = """+query Me{+ me{+ id+ orders(first:10){+ edges{+ node{+ number+ status+ }+ }+ }+ }+}+"""+++def get_own_data(api_client):+ variables = {}++ response = api_client.post_graphql(+ ME_QUERY,+ variables,+ )+ content = get_graphql_content(response)+ data = content["data"]["me"]+ assert data is not None++ return datadiff --git a/saleor/tests/e2e/checkout/test_buy_gift_card_in_the_checkout.py b/saleor/tests/e2e/checkout/test_buy_gift_card_in_the_checkout.pynew file mode 100644index 0000000000..5a27138091--- /dev/null+++ b/saleor/tests/e2e/checkout/test_buy_gift_card_in_the_checkout.py@@ -0,0 +1,168 @@+import pytest++from ..account.utils import get_own_data+from ..channel.utils.channel_update import update_channel+from ..gift_cards.utils import get_gift_cards+from ..orders.utils import order_query+from ..product.utils import (+ create_category,+ create_product,+ create_product_channel_listing,+ create_product_type,+ create_product_variant,+ create_product_variant_channel_listing,+)+from ..shop.utils import update_shop_settings+from ..shop.utils.preparing_shop import prepare_shop+from ..utils import assign_permissions+from .utils import (+ checkout_complete,+ checkout_create,+ checkout_dummy_payment_create,+)+++def prepare_product_gift_card(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+):+ product_type_data = create_product_type(+ e2e_staff_api_client,+ product_type_name="Gift card product type",+ slug="gc-type",+ is_shipping_required=False,+ is_digital=True,+ kind="GIFT_CARD",+ )+ assert product_type_data["kind"] == "GIFT_CARD"+ 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"]+ product_variant_price = 25++ create_product_variant_channel_listing(+ e2e_staff_api_client, product_variant_id, channel_id, product_variant_price+ )++ return product_variant_id, product_variant_price, product_id+++def test_buy_gift_card_in_the_checkout_CORE_1102(+ e2e_logged_api_client,+ e2e_staff_api_client,+ permission_manage_product_types_and_attributes,+ permission_manage_channels,+ permission_manage_products,+ permission_manage_shipping,+ permission_manage_gift_card,+ permission_manage_orders,+ permission_manage_settings,+ permission_manage_plugins,+):+ # Before+ permissions = [+ permission_manage_product_types_and_attributes,+ permission_manage_channels,+ permission_manage_products,+ permission_manage_shipping,+ permission_manage_gift_card,+ permission_manage_orders,+ permission_manage_settings,+ permission_manage_plugins,+ ]+ assign_permissions(e2e_staff_api_client, permissions)+ (+ warehouse_id,+ channel_id,+ channel_slug,+ _shipping_method_id,+ ) = prepare_shop(e2e_staff_api_client)++ product_variant_id, _product_variant_price, product_id = prepare_product_gift_card(+ e2e_staff_api_client,+ warehouse_id,+ channel_id,+ )+ channel_input = {+ "orderSettings": {"automaticallyFulfillNonShippableGiftCard": True}+ }+ update_channel(e2e_staff_api_client, channel_id, channel_input)+ shop_settings_input = {+ "fulfillmentAutoApprove": True,+ "fulfillmentAllowUnpaid": True,+ }+ update_shop_settings(e2e_staff_api_client, shop_settings_input)++ # Step 1 - Create checkout.+ lines = [+ {+ "variantId": product_variant_id,+ "quantity": 1,+ },+ ]+ checkout_data = checkout_create(+ e2e_logged_api_client,+ lines,+ channel_slug,+ email="[email protected]",+ set_default_billing_address=True,+ )+ checkout_id = checkout_data["id"]+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]+ assert checkout_data["isShippingRequired"] is False++ # Step 2 - Create payment for checkout.+ checkout_dummy_payment_create(+ e2e_logged_api_client,+ checkout_id,+ total_gross_amount,+ )++ # Step 3 - Complete checkout.+ order_data = checkout_complete(+ e2e_logged_api_client,+ checkout_id,+ )+ assert order_data["isShippingRequired"] is False+ assert order_data["total"]["gross"]["amount"] == total_gross_amount++ # extra query because order need a time to change status+ me = get_own_data(e2e_logged_api_client)+ assert len(me["orders"]["edges"]) == 1++ # 4 Get Order+ order = order_query(e2e_staff_api_client, order_data["id"])+ assert order["status"] == "FULFILLED"++ # Step 5 - Verify created gift card+ gift_cards_data = get_gift_cards(e2e_staff_api_client, 10)+ assert len(gift_cards_data) == 1diff --git a/saleor/tests/e2e/gift_cards/utils/__init__.py b/saleor/tests/e2e/gift_cards/utils/__init__.pyindex e2847dc704..a915e5f928 100644--- a/saleor/tests/e2e/gift_cards/utils/__init__.py+++ b/saleor/tests/e2e/gift_cards/utils/__init__.py@@ -1,5 +1,7 @@from .gift_card_create import create_gift_card+from .gift_cards_query import get_gift_cards__all__ = ["create_gift_card",+ "get_gift_cards",]diff --git a/saleor/tests/e2e/gift_cards/utils/gift_cards_query.py b/saleor/tests/e2e/gift_cards/utils/gift_cards_query.pynew file mode 100644index 0000000000..2b10e92b27--- /dev/null+++ b/saleor/tests/e2e/gift_cards/utils/gift_cards_query.py@@ -0,0 +1,34 @@+from ...utils import get_graphql_content++GIFT_CARDS_QUERY = """+query GiftCards($first: Int) {+ giftCards(first: $first) {+ edges {+ node {+ id+ code+ initialBalance {+ amount+ }+ }+ }+ }+}+"""+++def get_gift_cards(+ staff_api_client,+ first=10,+):+ variables = {+ "first": first,+ }++ response = staff_api_client.post_graphql(+ GIFT_CARDS_QUERY,+ variables,+ )+ content = get_graphql_content(response)+ data = content["data"]["giftCards"]["edges"]+ return datadiff --git a/saleor/tests/e2e/product/utils/product_type.py b/saleor/tests/e2e/product/utils/product_type.pyindex 1aff01533c..68320b2071 100644--- a/saleor/tests/e2e/product/utils/product_type.py+++ b/saleor/tests/e2e/product/utils/product_type.py@@ -40,6 +40,7 @@ def create_product_type(has_variants=False,product_attributes=None,variant_attributes=None,+ kind="NORMAL",):if not product_attributes:product_attributes = []@@ -56,6 +57,7 @@ def create_product_type("hasVariants": has_variants,"productAttributes": product_attributes,"variantAttributes": variant_attributes,+ "kind": kind,}}diff --git a/saleor/tests/e2e/shop/utils/shop_update_settings.py b/saleor/tests/e2e/shop/utils/shop_update_settings.pyindex 04c039ab5a..1e8cc3252c 100644--- a/saleor/tests/e2e/shop/utils/shop_update_settings.py+++ b/saleor/tests/e2e/shop/utils/shop_update_settings.py@@ -11,6 +11,7 @@ mutation ShopSettingsUpdate($input: ShopSettingsInput!) {shop {enableAccountConfirmationByEmailfulfillmentAutoApprove+ fulfillmentAllowUnpaid}}}