Skip to content

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

Add test for setting default email in creating checkout with authentication

Unknown1f69a2443b62
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
index fdf869e4c7..a57a01a4f9 100644
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -16,6 +16,7 @@ MUTATION_CHECKOUT_CREATE = """
checkout {
token,
id
+ email
}
errors {
field
@@ -82,6 +83,26 @@ def test_checkout_create_required_email(api_client, variant):
assert errors[0]['message'] == 'This field cannot be blank.'
+def test_checkout_create_default_email_for_logged_in_customer(
+ user_api_client, variant):
+ variant_id = graphene.Node.to_global_id('ProductVariant', variant.id)
+ variables = {
+ 'checkoutInput': {
+ 'lines': [{
+ 'quantity': 1,
+ 'variantId': variant_id}]}}
+ response = user_api_client.post_graphql(
+ MUTATION_CHECKOUT_CREATE, variables)
+ customer = user_api_client.user
+ content = get_graphql_content(response)
+ new_cart = Cart.objects.first()
+ assert new_cart is not None
+ checkout_data = content['data']['checkoutCreate']['checkout']
+ assert checkout_data['email'] == str(customer.email)
+ assert new_cart.user.id == customer.id
+ assert new_cart.email == customer.email
+
+
def test_checkout_create_logged_in_customer(user_api_client, variant):
variant_id = graphene.Node.to_global_id('ProductVariant', variant.id)
variables = {