Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HP-2266 | fix: handle updates profile's language and contact_method fields #475

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions profiles/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ def email_change_makes_it_unverified(item, field, value):

profile_had_primary_email = bool(profile.get_primary_email_value())

if language := profile_data.pop("language", None):
profile.language = language.value

if contact_method := profile_data.pop("contact_method", None):
profile.contact_method = contact_method.value

for field, value in profile_data.items():
setattr(profile, field, value)
profile.save()
Expand Down
7 changes: 7 additions & 0 deletions profiles/tests/test_gql_create_my_profile_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_normal_user_can_create_profile(
createMyProfile(
input: {
profile: {
language: FINNISH,
contactMethod: EMAIL,
nickname: "${nickname}",
addEmails: [
{emailType: ${email_type}, email:"${email}", primary: ${primary}}
Expand All @@ -30,6 +32,8 @@ def test_normal_user_can_create_profile(
}
) {
profile {
language,
contactMethod,
nickname,
emails {
edges {
Expand All @@ -53,6 +57,8 @@ def test_normal_user_can_create_profile(
expected_data = {
"createMyProfile": {
"profile": {
"language": "FINNISH",
"contactMethod": "EMAIL",
"nickname": profile_data["nickname"],
"emails": {
"edges": [
Expand All @@ -79,6 +85,7 @@ def test_normal_user_can_create_profile(
ssn=ssn,
)
executed = user_gql_client.execute(mutation)
assert "errors" not in executed
assert executed["data"] == expected_data


Expand Down
6 changes: 6 additions & 0 deletions profiles/tests/test_gql_create_profile_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_staff_user_can_create_a_profile(
input: {
serviceType: GODCHILDREN_OF_CULTURE,
profile: {
language: FINNISH,
contactMethod: EMAIL,
firstName: "${first_name}",
lastName: "${last_name}",
${email_input}
Expand All @@ -42,6 +44,8 @@ def test_staff_user_can_create_a_profile(
}
) {
profile {
language,
contactMethod,
firstName
lastName
phones {
Expand Down Expand Up @@ -97,6 +101,8 @@ def test_staff_user_can_create_a_profile(
expected_data = {
"createProfile": {
"profile": {
"language": "FINNISH",
"contactMethod": "EMAIL",
"firstName": "John",
"lastName": "Doe",
"phones": {
Expand Down
75 changes: 75 additions & 0 deletions profiles/tests/test_gql_update_my_profile_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from utils import keycloak

from ..helpers import to_global_id
from ..schema import ContactMethod, Language
from .factories import (
AddressFactory,
EmailFactory,
Expand Down Expand Up @@ -155,6 +156,80 @@ def test_update_profile_without_email(user_gql_client, profile_data):
assert executed["data"] == expected_data


@pytest.mark.parametrize("lang", Language, ids=repr)
def test_update_profile_language(user_gql_client, lang):
profile = ProfileWithPrimaryEmailFactory(user=user_gql_client.user)
t = Template(
"""
mutation {
updateMyProfile(
input: {
profile: {
language: ${language}
}
}
) {
profile {
language
}
}
}
"""
)
expected_data = {
"updateMyProfile": {
"profile": {
"language": lang.name,
}
}
}
mutation = t.substitute(language=lang.name)

executed = user_gql_client.execute(mutation)

assert "errors" not in executed
assert dict(executed["data"]) == expected_data
profile.refresh_from_db()
assert profile.language == lang.value


@pytest.mark.parametrize("contact_method", ContactMethod, ids=repr)
def test_update_profile_contact_method(user_gql_client, contact_method):
profile = ProfileWithPrimaryEmailFactory(user=user_gql_client.user)
t = Template(
"""
mutation {
updateMyProfile(
input: {
profile: {
contactMethod: ${contact_method}
}
}
) {
profile {
contactMethod
}
}
}
"""
)
expected_data = {
"updateMyProfile": {
"profile": {
"contactMethod": contact_method.name,
}
}
}
mutation = t.substitute(contact_method=contact_method.name)

executed = user_gql_client.execute(mutation)

assert "errors" not in executed
assert dict(executed["data"]) == expected_data
profile.refresh_from_db()
assert profile.contact_method == contact_method.value


def test_add_email(user_gql_client, email_data):
profile = ProfileWithPrimaryEmailFactory(user=user_gql_client.user)
email = profile.emails.first()
Expand Down