Skip to content

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

Update tests

Marcin Gębala79c3ca3c030d
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 577d981308..ff5077cb15 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -591,9 +591,10 @@ ACCOUNT_REGISTER_MUTATION = """
redirectUrl: $redirectUrl
}
) {
- errors {
+ accountErrors {
field
message
+ code
}
user {
id
@@ -622,16 +623,16 @@ def test_customer_register(
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"][mutation_name]
- assert not data["errors"]
+ assert not data["accountErrors"]
assert send_account_confirmation_email_mock.delay.call_count == 1
new_user = User.objects.get(email=email)
response = api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content["data"][mutation_name]
- assert data["errors"]
- assert data["errors"][0]["field"] == "email"
- assert data["errors"][0]["message"] == ("User with this Email already exists.")
+ assert data["accountErrors"]
+ assert data["accountErrors"][0]["field"] == "email"
+ assert data["accountErrors"][0]["code"] == AccountErrorCode.UNIQUE.name
customer_creation_event = account_events.CustomerEvent.objects.get()
assert customer_creation_event.type == account_events.CustomerEvents.ACCOUNT_CREATED
@@ -648,7 +649,7 @@ def test_customer_register_disabled_email_confirmation(
variables = {"email": email, "password": "Password"}
response = api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)
- errors = response.json()["data"]["accountRegister"]["errors"]
+ errors = response.json()["data"]["accountRegister"]["accountErrors"]
new_user = User.objects.get(email=email)
assert errors == []
@@ -663,7 +664,7 @@ def test_customer_register_no_redirect_url(
):
variables = {"email": "[email protected]", "password": "Password"}
response = api_client.post_graphql(ACCOUNT_REGISTER_MUTATION, variables)
- errors = response.json()["data"]["accountRegister"]["errors"]
+ errors = response.json()["data"]["accountRegister"]["accountErrors"]
assert "redirectUrl" in map(lambda error: error["field"], errors)
assert send_account_confirmation_email_mock.delay.call_count == 0
@@ -2167,9 +2168,13 @@ REQUEST_PASSWORD_RESET_MUTATION = """
CONFIRM_ACCOUNT_MUTATION = """
mutation ConfirmAccount($email: String!, $token: String!) {
confirmAccount(email: $email, token: $token) {
- errors {
+ accountErrors {
field
- message
+ code
+ }
+ user {
+ id
+ email
}
}
}
@@ -2204,8 +2209,8 @@ def test_account_confirmation(api_client, customer_user):
}
response = api_client.post_graphql(CONFIRM_ACCOUNT_MUTATION, variables)
content = get_graphql_content(response)
- assert not content["data"]["confirmAccount"]["errors"]
-
+ assert not content["data"]["confirmAccount"]["accountErrors"]
+ assert content["data"]["confirmAccount"]["user"]["email"] == customer_user.email
customer_user.refresh_from_db()
assert customer_user.is_active is True
@@ -2217,18 +2222,22 @@ def test_account_confirmation_invalid_user(user_api_client, customer_user):
}
response = user_api_client.post_graphql(CONFIRM_ACCOUNT_MUTATION, variables)
content = get_graphql_content(response)
- assert content["data"]["confirmAccount"]["errors"] == [
- {"field": "email", "message": "User with this email doesn't exist"}
- ]
+ assert content["data"]["confirmAccount"]["accountErrors"][0]["field"] == "email"
+ assert (
+ content["data"]["confirmAccount"]["accountErrors"][0]["code"]
+ == AccountErrorCode.NOT_FOUND.name
+ )
def test_account_confirmation_invalid_token(user_api_client, customer_user):
variables = {"email": customer_user.email, "token": "invalid_token"}
response = user_api_client.post_graphql(CONFIRM_ACCOUNT_MUTATION, variables)
content = get_graphql_content(response)
- assert content["data"]["confirmAccount"]["errors"] == [
- {"field": "token", "message": "Invalid or expired token."}
- ]
+ assert content["data"]["confirmAccount"]["accountErrors"][0]["field"] == "token"
+ assert (
+ content["data"]["confirmAccount"]["accountErrors"][0]["code"]
+ == AccountErrorCode.INVALID.name
+ )
@patch("saleor.account.emails._send_password_reset_email")
@@ -3258,6 +3267,20 @@ def test_request_email_change_with_invalid_redirect_url(
]
+def test_request_email_change_with_invalid_password(user_api_client, customer_user):
+ variables = {
+ "password": "spanishinquisition",
+ "new_email": "[email protected]",
+ "redirect_url": "http://www.example.com",
+ }
+ response = user_api_client.post_graphql(REQUEST_EMAIL_CHANGE_QUERY, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["requestEmailChange"]
+ assert not data["user"]
+ assert data["accountErrors"][0]["code"] == AccountErrorCode.INVALID_PASSWORD.name
+ assert data["accountErrors"][0]["field"] == "password"
+
+
EMAIL_UPDATE_QUERY = """
mutation emailUpdate($token: String!) {
confirmEmailChange(token: $token){