Skip to content

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

[TEST] Anonymous order should be assigned to the user CORE_1517 & CORE_1518 (#14691)

Renata28e8fb3989d8
diff --git a/saleor/tests/e2e/checkout/test_checkout_use_multiple_gift_cards.py b/saleor/tests/e2e/checkout/test_checkout_use_multiple_gift_cards.py
index f92f1b2fe7..1cd780937f 100644
--- a/saleor/tests/e2e/checkout/test_checkout_use_multiple_gift_cards.py
+++ b/saleor/tests/e2e/checkout/test_checkout_use_multiple_gift_cards.py
@@ -25,7 +25,15 @@ def prepare_gift_cards(
second_code = gift_card[1]["code"]
third_code = gift_card[2]["code"]
- return first_code, second_code, third_code, balance_amount
+ gift_card_codes = [first_code, second_code, third_code]
+
+ return (
+ first_code,
+ second_code,
+ third_code,
+ balance_amount,
+ gift_card_codes,
+ )
@pytest.mark.e2e
@@ -66,9 +74,13 @@ def test_use_multiple_gift_cards_in_checkout_core_1105(
variant_price=9.99,
)
product_variant_price = float(product_variant_price)
- first_code, second_code, third_code, balance_amount = prepare_gift_cards(
- e2e_staff_api_client, 3, 5
- )
+ (
+ first_code,
+ second_code,
+ third_code,
+ balance_amount,
+ gift_card_codes,
+ ) = prepare_gift_cards(e2e_staff_api_client, 3, 5)
# Step 1 - Create checkout for product
lines = [
@@ -158,6 +170,11 @@ def test_use_multiple_gift_cards_in_checkout_core_1105(
assert order_data["status"] == "UNFULFILLED"
assert order_data["shippingPrice"]["gross"]["amount"] == shipping_price
assert order_data["total"]["gross"]["amount"] == calculated_total
- assert order_data["giftCards"][0]["last4CodeChars"] == first_code[-4:]
- assert order_data["giftCards"][1]["last4CodeChars"] == second_code[-4:]
- assert order_data["giftCards"][2]["last4CodeChars"] == third_code[-4:]
+ assert len(order_data["giftCards"]) == 3
+
+ for i in range(3):
+ expected_last_4 = gift_card_codes[i][-4:]
+ actual_codes = [
+ gift_card["last4CodeChars"] for gift_card in order_data["giftCards"]
+ ]
+ assert any(expected_last_4 in code for code in actual_codes)
diff --git a/saleor/tests/e2e/checkout/test_guest_checkout_should_be_assigned_to_user_after_creating_the_account.py b/saleor/tests/e2e/checkout/test_guest_checkout_should_be_assigned_to_user_after_creating_the_account.py
new file mode 100644
index 0000000000..f77f1135c1
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_guest_checkout_should_be_assigned_to_user_after_creating_the_account.py
@@ -0,0 +1,148 @@
+import pytest
+
+from ..account.utils import account_register
+from ..product.utils.preparing_product import prepare_product
+from ..shop.utils import update_shop_settings
+from ..shop.utils.preparing_shop import prepare_shop
+from ..users.utils import customer_update, get_user
+from ..utils import assign_permissions
+from .utils import (
+ checkout_complete,
+ checkout_create,
+ checkout_delivery_method_update,
+ checkout_dummy_payment_create,
+)
+
+
+def test_guest_checkout_should_be_assigned_to_user_after_creating_the_account_CORE_1518(
+ e2e_staff_api_client,
+ app_api_client,
+ e2e_not_logged_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+ permission_manage_checkouts,
+ permission_manage_users,
+ permission_manage_settings,
+ permission_manage_payments,
+):
+ # Before
+ permissions = [
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+ permission_manage_checkouts,
+ permission_manage_users,
+ permission_manage_settings,
+ permission_manage_payments,
+ ]
+ assign_permissions(
+ app_api_client,
+ [
+ permission_manage_checkouts,
+ permission_manage_orders,
+ permission_manage_payments,
+ ],
+ )
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ (
+ warehouse_id,
+ channel_id,
+ channel_slug,
+ shipping_method_id,
+ ) = prepare_shop(e2e_staff_api_client)
+
+ input_data = {
+ "enableAccountConfirmationByEmail": False,
+ }
+ update_shop_settings(e2e_staff_api_client, input_data)
+
+ 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
+ email = "[email protected]"
+ lines = [
+ {
+ "variantId": product_variant_id,
+ "quantity": 1,
+ },
+ ]
+ checkout_data = checkout_create(
+ app_api_client,
+ lines,
+ channel_slug,
+ email,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+
+ assert checkout_data["isShippingRequired"] is True
+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]
+ assert checkout_data["deliveryMethod"] is None
+
+ # Step 2 - Set DeliveryMethod for checkout
+ checkout_data = checkout_delivery_method_update(
+ app_api_client,
+ checkout_id,
+ shipping_method_id,
+ )
+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+
+ # Step 3 - Create payment for checkout
+ checkout_dummy_payment_create(
+ app_api_client,
+ checkout_id,
+ total_gross_amount,
+ )
+
+ # Step 4 - Complete checkout
+ order_data = checkout_complete(
+ app_api_client,
+ checkout_id,
+ )
+ order_id = order_data["id"]
+ assert order_data["isShippingRequired"] is True
+ assert order_data["status"] == "UNFULFILLED"
+ assert order_data["total"]["gross"]["amount"] == total_gross_amount
+ assert order_data["deliveryMethod"]["id"] == shipping_method_id
+
+ # Step 5 - Register new account
+ password = "Test1234!"
+ redirect_url = "https://www.example.com"
+ user_account = account_register(
+ e2e_not_logged_api_client,
+ email,
+ password,
+ channel_slug,
+ redirect_url,
+ )
+ user_id = user_account["user"]["id"]
+ assert user_account["user"]["isActive"] is True
+
+ # Step 6 - Confirm new account
+ input_data = {"isConfirmed": True}
+ customer_update(e2e_staff_api_client, user_id, input_data)
+
+ # Step 7 - Check the order is assigned to the customer's account
+ data = get_user(e2e_staff_api_client, user_id)
+ assert data["id"] == user_id
+ assert data["orders"]["edges"][0]["node"]["id"] == order_id
diff --git a/saleor/tests/e2e/checkout/test_guest_checkout_should_be_associated_with_user_account.py b/saleor/tests/e2e/checkout/test_guest_checkout_should_be_associated_with_user_account.py
new file mode 100644
index 0000000000..da1be0ffef
--- /dev/null
+++ b/saleor/tests/e2e/checkout/test_guest_checkout_should_be_associated_with_user_account.py
@@ -0,0 +1,129 @@
+import pytest
+
+from ..product.utils.preparing_product import prepare_product
+from ..shop.utils.preparing_shop import prepare_shop
+from ..users.utils import create_customer, get_user
+from ..utils import assign_permissions
+from .utils import (
+ checkout_complete,
+ checkout_create,
+ checkout_delivery_method_update,
+ checkout_dummy_payment_create,
+)
+
+
+def create_active_customer(
+ e2e_staff_api_client,
+):
+ email = "[email protected]"
+
+ user_data = create_customer(
+ e2e_staff_api_client,
+ email,
+ is_active=True,
+ )
+ user_id = user_data["id"]
+
+ return user_id, email
+
+
+def test_guest_checkout_should_be_associated_with_user_account_CORE_1517(
+ e2e_staff_api_client,
+ e2e_not_logged_api_client,
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+ permission_manage_checkouts,
+ permission_manage_users,
+ permission_manage_settings,
+):
+ # Before
+ permissions = [
+ permission_manage_products,
+ permission_manage_channels,
+ permission_manage_shipping,
+ permission_manage_product_types_and_attributes,
+ permission_manage_orders,
+ permission_manage_checkouts,
+ permission_manage_users,
+ permission_manage_settings,
+ ]
+ 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,
+ )
+
+ user_id, email = create_active_customer(e2e_staff_api_client)
+
+ # Step 1 - Create checkout as a guest user
+ lines = [
+ {
+ "variantId": product_variant_id,
+ "quantity": 1,
+ },
+ ]
+ checkout_data = checkout_create(
+ e2e_not_logged_api_client,
+ lines,
+ channel_slug,
+ email,
+ set_default_billing_address=True,
+ set_default_shipping_address=True,
+ )
+ checkout_id = checkout_data["id"]
+
+ assert checkout_data["isShippingRequired"] is True
+ shipping_method_id = checkout_data["shippingMethods"][0]["id"]
+ assert checkout_data["deliveryMethod"] is None
+
+ # Step 2 - Set DeliveryMethod for checkout
+ checkout_data = checkout_delivery_method_update(
+ e2e_not_logged_api_client,
+ checkout_id,
+ shipping_method_id,
+ )
+ assert checkout_data["deliveryMethod"]["id"] == shipping_method_id
+ total_gross_amount = checkout_data["totalPrice"]["gross"]["amount"]
+
+ # Step 3 - Create payment for checkout
+ checkout_dummy_payment_create(
+ e2e_not_logged_api_client,
+ checkout_id,
+ total_gross_amount,
+ )
+
+ # Step 4 - Complete checkout.
+ order_data = checkout_complete(
+ e2e_not_logged_api_client,
+ checkout_id,
+ )
+ order_id = order_data["id"]
+ assert order_data["isShippingRequired"] is True
+ assert order_data["status"] == "UNFULFILLED"
+ assert order_data["total"]["gross"]["amount"] == total_gross_amount
+ assert order_data["deliveryMethod"]["id"] == shipping_method_id
+
+ # Step 5 - Check the order is assigned to the customer's account
+ data = get_user(e2e_staff_api_client, user_id)
+ assert data["id"] == user_id
+ assert data["orders"]["edges"][0]["node"]["id"] == order_id
diff --git a/saleor/tests/e2e/checkout/test_logged_in_customer_should_be_able_to_order_physical_product.py b/saleor/tests/e2e/checkout/test_logged_in_customer_should_be_able_to_order_physical_product.py
index 65e501953c..bf88608a48 100644
--- a/saleor/tests/e2e/checkout/test_logged_in_customer_should_be_able_to_order_physical_product.py
+++ b/saleor/tests/e2e/checkout/test_logged_in_customer_should_be_able_to_order_physical_product.py
@@ -96,7 +96,6 @@ def test_process_checkout_with_physical_product_CORE_0103(
checkout_id,
)
assert order_data["isShippingRequired"] is True
- assert order_data["user"]["email"] == expected_email
assert order_data["status"] == "UNFULFILLED"
assert order_data["total"]["gross"]["amount"] == total_gross_amount
assert order_data["deliveryMethod"]["id"] == shipping_method_id
diff --git a/saleor/tests/e2e/checkout/utils/checkout_complete.py b/saleor/tests/e2e/checkout/utils/checkout_complete.py
index 8baf0d4c1a..00c8c4b4a2 100644
--- a/saleor/tests/e2e/checkout/utils/checkout_complete.py
+++ b/saleor/tests/e2e/checkout/utils/checkout_complete.py
@@ -13,9 +13,6 @@ mutation CheckoutComplete($checkoutId: ID!) {
status
paymentStatus
isPaid
- user {
- email
- }
isShippingRequired
total {
gross {
diff --git a/saleor/tests/e2e/users/utils/__init__.py b/saleor/tests/e2e/users/utils/__init__.py
index 4cd4ff633c..6ccc8514bd 100644
--- a/saleor/tests/e2e/users/utils/__init__.py
+++ b/saleor/tests/e2e/users/utils/__init__.py
@@ -1,6 +1,7 @@
from .create_customer import create_customer
from .customer_bulk_update import customer_bulk_update
from .customer_update import customer_update
+from .get_user import get_user
from .staff_create import create_staff
from .staff_update import update_staff
@@ -10,4 +11,5 @@ __all__ = [
"customer_update",
"create_staff",
"update_staff",
+ "get_user",
]
diff --git a/saleor/tests/e2e/users/utils/create_customer.py b/saleor/tests/e2e/users/utils/create_customer.py
index ab7cfc4f29..1f1a79a3ee 100644
--- a/saleor/tests/e2e/users/utils/create_customer.py
+++ b/saleor/tests/e2e/users/utils/create_customer.py
@@ -31,12 +31,14 @@ def create_customer(
email,
metadata=None,
private_metadata=None,
+ is_active=False,
):
variables = {
"input": {
"email": email,
"metadata": metadata,
"privateMetadata": private_metadata,
+ "isActive": is_active,
}
}
diff --git a/saleor/tests/e2e/users/utils/get_user.py b/saleor/tests/e2e/users/utils/get_user.py
new file mode 100644
index 0000000000..4f4b8a5662
--- /dev/null
+++ b/saleor/tests/e2e/users/utils/get_user.py
@@ -0,0 +1,39 @@
+from ...utils import get_graphql_content
+
+USER_QUERY = """
+query CustomerDetails($id:ID!){
+ user(id: $id) {
+ id
+ email
+ isConfirmed
+ isActive
+ orders(first: 10){
+ edges {
+ node {
+ id
+ number
+ paymentStatus
+ created
+ }
+ }
+ }
+ }
+}
+"""
+
+
+def get_user(
+ staff_api_client,
+ user_id,
+):
+ variables = {"id": user_id}
+
+ response = staff_api_client.post_graphql(
+ USER_QUERY,
+ variables,
+ )
+ content = get_graphql_content(response)
+
+ data = content["data"]["user"]
+
+ return data