From 7ec26afeafbdad5c284d0946d109c9bc6fd94c20 Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Tue, 11 Jan 2022 18:58:52 +0100 Subject: [PATCH] GREG-165: Changing name of fields to make it easier to check if values can be updated --- .../src/routes/guest/register/index.test.tsx | 6 +-- frontend/src/routes/guest/register/index.tsx | 12 +++--- gregui/api/serializers/guest.py | 16 +++---- gregui/api/views/invitation.py | 10 ++--- gregui/tests/api/views/test_invitation.py | 42 +++++++++---------- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/frontend/src/routes/guest/register/index.test.tsx b/frontend/src/routes/guest/register/index.test.tsx index 8b09debb..18c27199 100644 --- a/frontend/src/routes/guest/register/index.test.tsx +++ b/frontend/src/routes/guest/register/index.test.tsx @@ -11,8 +11,8 @@ const testData = { person: { first_name: 'Test20', last_name: 'Tester', - mobile_phone: '+4797543910', - email: 'test@example.org', + private_mobile: '+4797543910', + private_email: 'test@example.org', fnr: '04062141242', passport: 'DK-123456', date_of_birth: '1995-02-25', @@ -46,7 +46,7 @@ test('Field showing values correctly', async () => { await screen.findByDisplayValue(testData.person.first_name) await screen.findByDisplayValue(testData.person.last_name) - await screen.findByDisplayValue(testData.person.email) + await screen.findByDisplayValue(testData.person.private_email) await screen.findByDisplayValue(testData.person.fnr) // Passport nationality. The i18n-mock sets up en as the i18n.language property, so look for the English name diff --git a/frontend/src/routes/guest/register/index.tsx b/frontend/src/routes/guest/register/index.tsx index 0e357969..fa8e32f1 100644 --- a/frontend/src/routes/guest/register/index.tsx +++ b/frontend/src/routes/guest/register/index.tsx @@ -36,8 +36,8 @@ type InvitationData = { person: { first_name: string last_name: string - email?: string - mobile_phone?: string + private_email?: string + private_mobile?: string fnr?: string passport?: string feide_id?: string @@ -121,8 +121,8 @@ export default function GuestRegister() { ? AuthenticationMethod.Invite : AuthenticationMethod.Feide - const [countryCode, nationalNumber] = data.person.mobile_phone - ? splitPhoneNumber(data.person.mobile_phone) + const [countryCode, nationalNumber] = data.person.private_mobile + ? splitPhoneNumber(data.person.private_mobile) : ['', ''] let extractedCountryCode = '' @@ -155,7 +155,7 @@ export default function GuestRegister() { last_name: data.person.last_name ?? '', date_of_birth: dateOfBirth, gender: data.person.gender ?? '', - email: data.person.email ?? '', + email: data.person.private_email ?? '', feide_id: data.person.feide_id ?? '', fnr: data.person.fnr ?? '', passport: passportNumber ?? '', @@ -227,7 +227,7 @@ export default function GuestRegister() { const payload: any = { person: {}, } - payload.person.mobile_phone = `+${getCountryCallingCode( + payload.person.private_mobile = `+${getCountryCallingCode( registerData.mobilePhoneCountry as CountryCode )}${registerData.mobilePhone}` diff --git a/gregui/api/serializers/guest.py b/gregui/api/serializers/guest.py index 5198622d..255ddf63 100644 --- a/gregui/api/serializers/guest.py +++ b/gregui/api/serializers/guest.py @@ -31,8 +31,8 @@ class GuestRegisterSerializer(serializers.ModelSerializer): last_name = serializers.CharField(required=False, min_length=1) # E-mail set to not required to avoid raising exception if it is not included in input. It is not given that # the guest should be allowed to update it - email = serializers.CharField(required=False) - mobile_phone = serializers.CharField( + private_email = serializers.CharField(required=False) + private_mobile = serializers.CharField( required=True, validators=[validate_phone_number] ) fnr = serializers.CharField( @@ -44,14 +44,14 @@ class GuestRegisterSerializer(serializers.ModelSerializer): consents = GuestConsentChoiceSerializer(required=False, many=True, write_only=True) def update(self, instance, validated_data): - if "email" in validated_data: - email = validated_data.pop("email") + if "private_email" in validated_data: + email = validated_data.pop("private_email") create_identity_or_update( Identity.IdentityType.PRIVATE_EMAIL, email, instance ) - if "mobile_phone" in validated_data: - mobile_phone = validated_data.pop("mobile_phone") + if "private_mobile" in validated_data: + mobile_phone = validated_data.pop("private_mobile") create_identity_or_update( Identity.IdentityType.PRIVATE_MOBILE_NUMBER, mobile_phone, instance ) @@ -138,8 +138,8 @@ class GuestRegisterSerializer(serializers.ModelSerializer): "first_name", "last_name", "gender", - "email", - "mobile_phone", + "private_email", + "private_mobile", "fnr", "passport", "date_of_birth", diff --git a/gregui/api/views/invitation.py b/gregui/api/views/invitation.py index 39802970..eaa9dd80 100644 --- a/gregui/api/views/invitation.py +++ b/gregui/api/views/invitation.py @@ -189,16 +189,16 @@ class InvitedGuestView(GenericAPIView): fields_allowed_to_update_if_invite = [ "first_name", "last_name", - "email", + "private_email", "fnr", - "mobile_phone", + "private_mobile", "passport", "date_of_birth", "consents", "gender", ] fields_allowed_to_update_if_feide = [ - "mobile_phone", + "private_mobile", "passport", "consents", "gender", @@ -243,8 +243,8 @@ class InvitedGuestView(GenericAPIView): "person": { "first_name": person.first_name, "last_name": person.last_name, - "email": person.private_email and person.private_email.value, - "mobile_phone": person.private_mobile and person.private_mobile.value, + "private_email": person.private_email and person.private_email.value, + "private_mobile": person.private_mobile and person.private_mobile.value, "date_of_birth": person.date_of_birth, "fnr": person.fnr and person.fnr.value, "passport": person.passport and person.passport.value, diff --git a/gregui/tests/api/views/test_invitation.py b/gregui/tests/api/views/test_invitation.py index 4b6e1744..830fdbfc 100644 --- a/gregui/tests/api/views/test_invitation.py +++ b/gregui/tests/api/views/test_invitation.py @@ -87,8 +87,8 @@ def test_get_invited_info_session_okay( assert data.get("person") == dict( first_name=person.first_name, last_name=person.last_name, - email=person.private_email.value, - mobile_phone=None, + privat_email=person.private_email.value, + private_mobile=None, fnr=None, passport=None, feide_id=None, @@ -144,7 +144,7 @@ def test_invited_guest_can_post_information( # post updated info to confirm from guest new_email = "private@example.org" new_phone = "+4790000000" - data = {"person": {"mobile_phone": new_phone, "email": new_email}} + data = {"person": {"private_mobile": new_phone, "private_email": new_email}} response = client.post( reverse("gregui-v1:invited-info"), @@ -197,8 +197,8 @@ def test_post_invited_info_invalid_national_id_number(client, invited_person): person, invitation_link = invited_person data = { "person": { - "mobile_phone": "+4707543001", - "email": "test@example.com", + "private_mobile": "+4707543001", + "private_email": "test@example.com", "fnr": "123", } } @@ -226,8 +226,8 @@ def test_post_invited_info_valid_national_id_number( fnr = "11120618212" data = { "person": { - "mobile_phone": "+4797543992", - "email": "test@example.com", + "private_mobile": "+4797543992", + "private_email": "test@example.com", "fnr": fnr, } } @@ -259,7 +259,7 @@ def test_email_update(client, invited_person, confirmation_template): session["invite_id"] = str(invitation_link.uuid) session.save() - data = {"person": {"mobile_phone": "+4797543992", "email": "test2@example.com"}} + data = {"person": {"private_mobile": "+4797543992", "private_email": "test2@example.com"}} response = client.post(url, data, format="json") assert response.status_code == status.HTTP_200_OK, response.data @@ -271,7 +271,7 @@ def test_email_update(client, invited_person, confirmation_template): def test_register_passport(client, invited_person, confirmation_template): person, invitation_link = invited_person passport_information = "EN-123456789" - data = {"person": {"mobile_phone": "+4797543992", "passport": passport_information}} + data = {"person": {"private_mobile": "+4797543992", "passport": passport_information}} url = reverse("gregui-v1:invited-info") session = client.session @@ -325,7 +325,7 @@ def test_name_update_not_allowed_if_feide_identity_is_present( "person": { "first_name": "Someone", "last_name": "Test", - "mobile_phone": "+4797543992", + "private_mobile": "+4797543992", } } @@ -374,7 +374,7 @@ def test_name_update_allowed_if_feide_identity_is_not_present( "person": { "first_name": "Someone", "last_name": "Test", - "mobile_phone": "+4797543992", + "private_mobile": "+4797543992", } } @@ -403,7 +403,7 @@ def test_post_info_fail_fnr_already_verified(client, invited_person_verified_nin session.save() url = reverse("gregui-v1:invited-info") - data = {"person": {"mobile_phone": "+4797543992", "fnr": fnr}} + data = {"person": {"private_mobile": "+4797543992", "fnr": fnr}} response = client.post(url, data, format="json") # Verify rejection @@ -424,7 +424,7 @@ def test_post_info_fail_unknown_field(client, invited_person_verified_nin): session.save() url = reverse("gregui-v1:invited-info") - data = {"person": {"mobile_phone": "+4797543992", "badfield": "foo"}} + data = {"person": {"private_mobile": "+4797543992", "badfield": "foo"}} response = client.post(url, data, format="json") # Verify rejection @@ -443,7 +443,7 @@ def test_date_of_birth_stored( date_of_birth = "1995-10-28" url = reverse("gregui-v1:invited-info") - data = {"person": {"mobile_phone": "+4797543992", "date_of_birth": date_of_birth}} + data = {"person": {"private_mobile": "+4797543992", "date_of_birth": date_of_birth}} response = client.post(url, data, format="json") assert response.status_code == status.HTTP_200_OK @@ -465,7 +465,7 @@ def test_invalid_date_of_birth_rejected(client, invited_person_verified_nin): date_of_birth = "1900-03-16" url = reverse("gregui-v1:invited-info") - data = {"person": {"mobile_phone": "+4797543992", "date_of_birth": date_of_birth}} + data = {"person": {"private_mobile": "+4797543992", "date_of_birth": date_of_birth}} response = client.post(url, data, format="json") assert response.status_code == status.HTTP_400_BAD_REQUEST @@ -490,7 +490,7 @@ def test_saves_consents( {"type": consent_type_bar.identifier, "choice": "yes"}, ] - data = {"person": {"mobile_phone": "+4797543992", "fnr": fnr, "consents": consents}} + data = {"person": {"private_mobile": "+4797543992", "fnr": fnr, "consents": consents}} url = reverse("gregui-v1:invited-info") response = client.post(url, data, format="json") @@ -516,8 +516,8 @@ def test_post_invited_info_valid_dnumber(client, invited_person, confirmation_te d_number = "53097248016" data = { "person": { - "mobile_phone": "+4797543992", - "email": "test@example.com", + "private_mobile": "+4797543992", + "private_email": "test@example.com", "fnr": d_number, } } @@ -548,7 +548,7 @@ def test_gender_stored(client, invited_person_verified_nin, confirmation_templat url = reverse("gregui-v1:invited-info") data = { "person": { - "mobile_phone": "+4797543992", + "private_mobile": "+4797543992", "date_of_birth": date_of_birth, "gender": "male", } @@ -573,7 +573,7 @@ def test_gender_blank_allowed( date_of_birth = "1995-10-28" url = reverse("gregui-v1:invited-info") - data = {"person": {"mobile_phone": "+4797543992", "date_of_birth": date_of_birth}} + data = {"person": {"private_mobile": "+4797543992", "date_of_birth": date_of_birth}} response = client.post(url, data, format="json") assert response.status_code == status.HTTP_200_OK @@ -594,7 +594,7 @@ def test_invalid_gender_rejected(client, invited_person_verified_nin): url = reverse("gregui-v1:invited-info") data = { "person": { - "mobile_phone": "+4797543992", + "private_mobile": "+4797543992", "date_of_birth": date_of_birth, "gender": "abcdefg", } -- GitLab