Skip to content

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

[TEST] Should be able to create account and login (#13397)

Anna Szczęch5036b7451459
diff --git a/saleor/tests/e2e/account/__init__.py b/saleor/tests/e2e/account/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/account/test_should_create_account_without_email_confirmation.py b/saleor/tests/e2e/account/test_should_create_account_without_email_confirmation.py
new file mode 100644
index 0000000000..e7b9c618b3
--- /dev/null
+++ b/saleor/tests/e2e/account/test_should_create_account_without_email_confirmation.py
@@ -0,0 +1,43 @@
+import pytest
+
+from ..channel.utils import create_channel
+from ..shop.utils import update_shop_settings
+from ..utils import assign_permissions
+from .utils import account_register, token_create
+
+
+def test_should_create_account_without_email_confirmation_core_1502(
+ e2e_not_logged_api_client,
+ e2e_staff_api_client,
+ permission_manage_channels,
+ permission_manage_settings,
+):
+ # Before
+ permissions = [permission_manage_channels, permission_manage_settings]
+ assign_permissions(e2e_staff_api_client, permissions)
+
+ chanel_data = create_channel(e2e_staff_api_client)
+ channel_slug = chanel_data["slug"]
+
+ update_shop_settings(e2e_staff_api_client, enableAccountConfirmationByEmail=False)
+
+ test_email = "[email protected]"
+ test_password = "password!"
+
+ # Step 1 - Create account for the new customer
+ user_account = account_register(
+ e2e_not_logged_api_client,
+ test_email,
+ test_password,
+ channel_slug,
+ )
+ user_id = user_account["id"]
+ assert user_account["isActive"] is True
+
+ # Step 2 - Authenticate as new created user
+
+ login_data = token_create(e2e_not_logged_api_client, test_email, test_password)
+
+ assert login_data["id"] == user_id
+ assert login_data["email"] == test_email
diff --git a/saleor/tests/e2e/account/utils/__init__.py b/saleor/tests/e2e/account/utils/__init__.py
new file mode 100644
index 0000000000..e78882a5b5
--- /dev/null
+++ b/saleor/tests/e2e/account/utils/__init__.py
@@ -0,0 +1,7 @@
+from .account_register import account_register
+from .token_create import token_create
+
+__all__ = [
+ "account_register",
+ "token_create",
+]
diff --git a/saleor/tests/e2e/account/utils/account_register.py b/saleor/tests/e2e/account/utils/account_register.py
new file mode 100644
index 0000000000..af928fccac
--- /dev/null
+++ b/saleor/tests/e2e/account/utils/account_register.py
@@ -0,0 +1,48 @@
+from ...utils import get_graphql_content
+
+ACCOUNT_REGISTER_MUTATION = """
+mutation AccountRegister($input: AccountRegisterInput!) {
+ accountRegister(input: $input) {
+ errors {
+ field
+ message
+ code
+ }
+ requiresConfirmation
+ user {
+ id
+ email
+ isActive
+ }
+ }
+}
+"""
+
+
+def account_register(
+ e2e_not_logged_api_client,
+ email,
+ password,
+ channel_slug,
+):
+ variables = {
+ "input": {
+ "email": email,
+ "password": password,
+ "channel": channel_slug,
+ }
+ }
+
+ response = e2e_not_logged_api_client.post_graphql(
+ ACCOUNT_REGISTER_MUTATION,
+ variables,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["accountRegister"]["errors"] == []
+
+ data = content["data"]["accountRegister"]["user"]
+ assert data["id"] is not None
+ assert data["email"] == email
+
+ return data
diff --git a/saleor/tests/e2e/account/utils/token_create.py b/saleor/tests/e2e/account/utils/token_create.py
new file mode 100644
index 0000000000..22995b2a1d
--- /dev/null
+++ b/saleor/tests/e2e/account/utils/token_create.py
@@ -0,0 +1,44 @@
+from ...utils import get_graphql_content
+
+TOKEN_CREATE_MUTATION = """
+mutation TokenCreate($email: String!, $password: String!) {
+ tokenCreate(email: $email, password: $password) {
+ errors {
+ field
+ message
+ code
+ }
+ token
+ refreshToken
+ user {
+ id
+ email
+ }
+ }
+}
+"""
+
+
+def token_create(
+ e2e_not_logged_api_client,
+ email,
+ password,
+):
+ variables = {"email": email, "password": password}
+
+ response = e2e_not_logged_api_client.post_graphql(
+ TOKEN_CREATE_MUTATION,
+ variables,
+ )
+ content = get_graphql_content(response)
+
+ assert content["data"]["tokenCreate"]["errors"] == []
+
+ assert content["data"]["tokenCreate"]["token"] is not None
+ assert content["data"]["tokenCreate"]["refreshToken"] is not None
+
+ data = content["data"]["tokenCreate"]["user"]
+ assert data["id"] is not None
+ assert data["email"] == email
+
+ return data
diff --git a/saleor/tests/e2e/shop/__init__.py b/saleor/tests/e2e/shop/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/tests/e2e/shop/utils.py b/saleor/tests/e2e/shop/utils.py
new file mode 100644
index 0000000000..4e0074af3e
--- /dev/null
+++ b/saleor/tests/e2e/shop/utils.py
@@ -0,0 +1,34 @@
+from ..utils import get_graphql_content
+
+SHOP_SETTING_UPDATE_MUTATION = """
+mutation ShopSettingsUpdate($input: ShopSettingsInput!) {
+ shopSettingsUpdate(input: $input) {
+ errors {
+ field
+ message
+ code
+ }
+ shop {
+ enableAccountConfirmationByEmail
+ }
+ }
+}
+"""
+
+
+def update_shop_settings(staff_api_client, enableAccountConfirmationByEmail=False):
+ variables = {
+ "input": {
+ "enableAccountConfirmationByEmail": enableAccountConfirmationByEmail,
+ }
+ }
+
+ response = staff_api_client.post_graphql(SHOP_SETTING_UPDATE_MUTATION, variables)
+ content = get_graphql_content(response)
+
+ assert content["data"]["shopSettingsUpdate"]["errors"] == []
+
+ data = content["data"]["shopSettingsUpdate"]["shop"]
+ assert data["enableAccountConfirmationByEmail"] == enableAccountConfirmationByEmail
+
+ return data