From 98d820a199495c83eb1409049425068616f8e352 Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Wed, 15 Nov 2023 08:13:34 +0000 Subject: [PATCH 1/8] update content --- .../gafl-webapp-service/src/locales/en.json | 15 ++- .../src/pages/contact/contact/contact.njk | 107 +++++++++++++----- 2 files changed, 88 insertions(+), 34 deletions(-) diff --git a/packages/gafl-webapp-service/src/locales/en.json b/packages/gafl-webapp-service/src/locales/en.json index 22a0a55bc4..e1107593af 100644 --- a/packages/gafl-webapp-service/src/locales/en.json +++ b/packages/gafl-webapp-service/src/locales/en.json @@ -289,21 +289,26 @@ "important_info_contact_input_email_hint": "For example name@example.com", "important_info_contact_input_email": "Email address", "important_info_contact_input_mobile_hint": "For example 07700 900 900", - "important_info_contact_input_mobile_note": "Mobile phone number", + "important_info_contact_input_mobile_note": "UK mobile number", "important_info_contact_input_mobile": "UK mobile phone number", "important_info_contact_item_email": "Email", "important_info_contact_item_txt": "Text message", + "important_info_contact_item_txt_value": "Text message to ", "important_info_contact_licence_needed": "The rod licence holder will need to confirm the licence number if asked by an enforcement officer.", "important_info_contact_none_msg": "We will show you the licence number on confirmation.", "important_info_contact_note_tip": "Make a note of the licence number", + "important_info_contact_post_hint_you": "By choosing post, you will not get a personalised link to renew your licence online before it expires.", + "important_info_contact_post_hint_other": "By choosing post, the licence holder will not get a personalised link to renew their licence online before it expires.", "important_info_contact_post_confirm_8d": "We don’t provide physical cards for 1 or 8 day licences.", "important_info_contact_post_confirm_jr": "We don’t provide physical cards for junior licences.", - "important_info_contact_post_confirm": "This is where we will send renewal reminders when the licence is ending.", - "important_info_contact_post_confirm2": "We will also send important information like byelaw updates.", + "important_info_contact_post_salmon_you": "We will send a renewal reminder before your licence expires and a reminder to report a catch return. We will also send other important updates, like rod fishing byelaw changes.", + "important_info_contact_post_not_salmon_you": "We will send a renewal reminder before your licence expires. We will also send other important updates, like rod fishing byelaw changes.", + "important_info_contact_post_salmon_other": "We will send a renewal reminder before the licence expires and a reminder to report a catch return. We will also send other important updates, like rod fishing byelaw changes.", + "important_info_contact_post_not_salmon_other": "We will send a renewal reminder before the licence expires. We will also send other important updates, like rod fishing byelaw changes.", "important_info_contact_post_msg": "If you want to fish before you receive the card you should make a note of the licence number after payment.", "important_info_contact_post": "Post", - "important_info_contact_title_other": "How should we contact the licence holder about reminders and important changes?", - "important_info_contact_title_you": "How should we contact you with reminders and important changes?", + "important_info_contact_title_other": "How should we contact the licence holder about updates affecting their licence?", + "important_info_contact_title_you": "How should we contact you about updates affecting your licence?", "licence_confirm_method_error_choose": "Choose how we should send the licence", "licence_confirm_method_how_body_item": "I will make a note of the licence number", "licence_confirm_method_how_body_text": "This is where we will send confirmation of the fishing licence", diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk b/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk index 5036fafb05..860df9aabb 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk +++ b/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk @@ -52,7 +52,6 @@
{{ mssgs.important_info_contact_input_email }}
{{ data.licensee.email }} -   {{ mssgs.licence_summary_change }}
{% endset -%} @@ -81,7 +80,6 @@
{{ mssgs.important_info_contact_input_mobile_note }}
{{ data.licensee.mobilePhone }} -   {{ mssgs.licence_summary_change }}
{% endset -%} @@ -94,34 +92,74 @@

{{ mssgs.important_info_contact_none_msg }}

{% endset -%} -{% set itemsArray = [ - { - value: "email", - text: mssgs.important_info_contact_item_email, - checked: payload['how-contacted'] === 'email', - conditional: { - html: emailHtml - } - }, - { - value: "text", - text: mssgs.important_info_contact_item_txt, - checked: payload['how-contacted'] === 'text', - conditional: { - html: textMessageHtml - } - } -] %} +{% set itemsArray = [] %} +{% if data.licensee.email %} + {% set itemsArray = (itemsArray.push( + { + value: "email", + text: mssgs.important_info_contact_item_email ~ data.licensee.email, + checked: payload['how-contacted'] === 'email' + }), itemsArray) + %} +{% else %} + {% set itemsArray = (itemsArray.push( + { + value: "email", + text: mssgs.important_info_contact_item_email, + checked: payload['how-contacted'] === 'email', + conditional: { + html: emailHtml + } + }), itemsArray) + %} +{% endif %} + +{% if data.licensee.mobilePhone %} + {% set itemsArray = (itemsArray.push( + { + value: "text", + text: mssgs.important_info_contact_item_txt_value ~ data.licensee.mobilePhone, + checked: payload['how-contacted'] === 'text' + }), itemsArray) + %} +{% else %} + {% set itemsArray = (itemsArray.push( + { + value: "text", + text: mssgs.important_info_contact_item_txt, + checked: payload['how-contacted'] === 'text', + conditional: { + html: textMessageHtml + } + }), itemsArray) + %} +{% endif %} {% if data.isPhysical %} {% if data.licensee.postalFulfilment %} - {% set itemsArray = (itemsArray.push( - { - value: "none", - text: mssgs.important_info_contact_post, - checked: payload['how-contacted'] === 'post' - }), itemsArray) - %} + {% if data.isLicenceForYou %} + {% set itemsArray = (itemsArray.push( + { + value: "none", + text: mssgs.important_info_contact_post, + checked: payload['how-contacted'] === 'post', + hint: { + text: mssgs.important_info_contact_post_hint_you + } + }), itemsArray) + %} + {% else %} + {% set itemsArray = (itemsArray.push( + { + value: "none", + text: mssgs.important_info_contact_post, + checked: payload['how-contacted'] === 'post', + hint: { + text: mssgs.important_info_contact_post_hint_other + } + }), itemsArray) + %} + {% endif %} {% endif %} {% else %} {% set itemsArray = (itemsArray.push( @@ -138,8 +176,19 @@ {% block pageContent %} {% if data.isPhysical %} -

{{ mssgs.important_info_contact_post_confirm }}

-

{{ mssgs.important_info_contact_post_confirm2 }}

+ {% if data.isLicenceForYou %} + {% if data.licensee.isSalmon %} +

{{ mssgs.important_info_contact_post_salmon_you }}

+ {% else %} +

{{ mssgs.important_info_contact_post_not_salmon_you }}

+ {% endif %} + {% else %} + {% if data.licensee.isSalmon %} +

{{ mssgs.important_info_contact_post_salmon_other }}

+ {% else %} +

{{ mssgs.important_info_contact_post_not_salmon_other }}

+ {% endif %} + {% endif %} {% else %} {% if data.isJunior %}

{{ mssgs.important_info_contact_post_confirm_jr }}

From 8c37217bfa0e4886192d1fd5bd3b74240111d802 Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Wed, 15 Nov 2023 10:43:47 +0000 Subject: [PATCH 2/8] move logic to route and add tests --- .../contact/contact/__tests__/route.spec.js | 102 ++++++++++++++---- .../src/pages/contact/contact/contact.njk | 57 +++------- .../src/pages/contact/contact/route.js | 9 +- 3 files changed, 108 insertions(+), 60 deletions(-) diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js index 08a9e0aca9..a09d82be81 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js @@ -2,6 +2,7 @@ import { getData, validator } from '../route' import pageRoute from '../../../../routes/page-route.js' import { nextPage } from '../../../../routes/next-page.js' import { isPhysical } from '../../../../processors/licence-type-display.js' +import { hasJunior } from '../../../../processors/concession-helper.js' jest.mock('../../../../routes/next-page.js', () => ({ nextPage: jest.fn() @@ -15,46 +16,111 @@ jest.mock('../../../../uri.js', () => ({ } })) jest.mock('../../../../processors/licence-type-display.js') +jest.mock('../../../../processors/concession-helper.js') describe('name > route', () => { - const getMockRequest = (isLicenceForYou = true) => ({ + const getMockRequest = ({ isLicenceForYou, licenceType, email, mobilePhone }) => ({ cache: () => ({ helpers: { transaction: { getCurrentPermission: () => ({ licensee: { - birthDate: 'birthDate' + birthDate: 'birthDate', + email, + mobilePhone }, licenceLength: 'licenceLength', licenceStartDate: 'licenceStartDate', - isLicenceForYou + isLicenceForYou, + licenceType }) } } - }) + }), + i18n: { + getCatalog: () => getMessages() + } + }) + + const getMessages = () => ({ + important_info_contact_title_you: 'You title', + important_info_contact_title_other: 'Other title', + important_info_contact_item_email: 'Email', + important_info_contact_item_txt_value: 'Text to ', + important_info_contact_item_txt: 'Text', + important_info_contact_post_hint_you: 'Post hint you', + important_info_contact_post_hint_other: 'Post hint other', + important_info_contact_post_salmon_you: 'Salmon you', + important_info_contact_post_not_salmon_you: 'Not salmon you', + important_info_contact_post_salmon_other: 'Salmon other', + important_info_contact_post_not_salmon_other: 'Not salmon other' }) describe('getData', () => { - it('should return isLicenceForYou as true, if isLicenceForYou is true on the transaction cache', async () => { - const result = await getData(getMockRequest(true)) - expect(result.isLicenceForYou).toBeTruthy() + it.each([ + [true, 'You title'], + [false, 'Other title'] + ])('title return method is %s if isLicenceForYou is same', async (isLicenceForYou, expected) => { + const result = await getData(getMockRequest({ isLicenceForYou })) + expect(result.title).toBe(expected) + }) + + it.each([ + ['test@email.com', 'Email test@email.com'], + [null, 'Email'] + ])('emailText has correct value depedning on if permission has an email', async (email, expected) => { + const result = await getData(getMockRequest({ email })) + expect(result.emailText).toBe(expected) + }) + + it.each([ + ['07123456789', 'Text to 07123456789'], + [null, 'Text'] + ])('mobileText has correct value depedning on if permission has a phone number', async (mobilePhone, expected) => { + const result = await getData(getMockRequest({ mobilePhone })) + expect(result.mobileText).toBe(expected) + }) + + it.each([ + [true, 'Post hint you'], + [false, 'Post hint other'] + ])('postHint wording depending on whether isLicenceForYou is %s', async (isLicenceForYou, expected) => { + const result = await getData(getMockRequest({ isLicenceForYou })) + expect(result.postHint).toBe(expected) + }) + + it.each([ + [true, 'Salmon and sea trout', 'Salmon you'], + [true, 'Trout and coarse', 'Not salmon you'], + [false, 'Salmon and sea trout', 'Salmon other'], + [false, 'Trout and coarse', 'Not salmon other'] + ])('content has correct value depending on isLicenceForYou is %s and licenceType is %s', async (isLicenceForYou, licenceType, expected) => { + const result = await getData(getMockRequest({ isLicenceForYou, licenceType })) + expect(result.content).toBe(expected) }) - it('should return isLicenceForYou as false, if isLicenceForYou is false on the transaction cache', async () => { - const result = await getData(getMockRequest(false)) - expect(result.isLicenceForYou).toBeFalsy() + it.each([ + [true, true], + [false, false] + ])('result.isPhysical matches return method of isPhysical', async (physical, expected) => { + isPhysical.mockReturnValueOnce(physical) + const result = await getData(getMockRequest({})) + expect(result.isPhysical).toBe(expected) }) - it('return isPhysical as true, if isPhysical is true for the permission', async () => { - isPhysical.mockReturnValueOnce(true) - const result = await getData(getMockRequest()) - expect(result.isPhysical).toBeTruthy() + it.each([ + [true, true], + [false, false] + ])('isJunior matches return method of hasJunior', async (physical, expected) => { + hasJunior.mockReturnValueOnce(physical) + const result = await getData(getMockRequest({})) + expect(result.isJunior).toBe(expected) }) - it('return isPhysical as false, if isPhysical is false for the permission', async () => { - isPhysical.mockReturnValueOnce(false) - const result = await getData(getMockRequest()) - expect(result.isPhysical).toBeFalsy() + it('howContacted returns the value of HOW_CONTACTED', async () => { + const expectedValue = { email: 'Email', text: 'Text', letter: 'Letter', none: 'Prefer not to be contacted' } + const result = await getData(getMockRequest({})) + expect(result.howContacted).toEqual(expectedValue) }) }) diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk b/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk index 860df9aabb..665a7217c9 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk +++ b/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk @@ -3,7 +3,7 @@ {% from "input/macro.njk" import govukInput %} {% from "warning-text/macro.njk" import govukWarningText %} -{% set title = mssgs.important_info_contact_title_you if data.isLicenceForYou else mssgs.important_info_contact_title_other %} +{% set title = data.title %} {% set errorMsg = mssgs.important_info_contact_error_choose %} {% set emailError = mssgs.important_info_contact_error_email %} {% set mobileError = mssgs.important_info_contact_error_mobile %} @@ -97,7 +97,7 @@ {% set itemsArray = (itemsArray.push( { value: "email", - text: mssgs.important_info_contact_item_email ~ data.licensee.email, + text: data.emailText, checked: payload['how-contacted'] === 'email' }), itemsArray) %} @@ -105,7 +105,7 @@ {% set itemsArray = (itemsArray.push( { value: "email", - text: mssgs.important_info_contact_item_email, + text: data.emailText, checked: payload['how-contacted'] === 'email', conditional: { html: emailHtml @@ -118,7 +118,7 @@ {% set itemsArray = (itemsArray.push( { value: "text", - text: mssgs.important_info_contact_item_txt_value ~ data.licensee.mobilePhone, + text: data.mobileText, checked: payload['how-contacted'] === 'text' }), itemsArray) %} @@ -126,7 +126,7 @@ {% set itemsArray = (itemsArray.push( { value: "text", - text: mssgs.important_info_contact_item_txt, + text: data.mobileText, checked: payload['how-contacted'] === 'text', conditional: { html: textMessageHtml @@ -137,29 +137,16 @@ {% if data.isPhysical %} {% if data.licensee.postalFulfilment %} - {% if data.isLicenceForYou %} - {% set itemsArray = (itemsArray.push( - { - value: "none", - text: mssgs.important_info_contact_post, - checked: payload['how-contacted'] === 'post', - hint: { - text: mssgs.important_info_contact_post_hint_you - } - }), itemsArray) - %} - {% else %} - {% set itemsArray = (itemsArray.push( - { - value: "none", - text: mssgs.important_info_contact_post, - checked: payload['how-contacted'] === 'post', - hint: { - text: mssgs.important_info_contact_post_hint_other - } - }), itemsArray) - %} - {% endif %} + {% set itemsArray = (itemsArray.push( + { + value: "none", + text: mssgs.important_info_contact_post, + checked: payload['how-contacted'] === 'post', + hint: { + text: data.postHint + } + }), itemsArray) + %} {% endif %} {% else %} {% set itemsArray = (itemsArray.push( @@ -176,19 +163,7 @@ {% block pageContent %} {% if data.isPhysical %} - {% if data.isLicenceForYou %} - {% if data.licensee.isSalmon %} -

{{ mssgs.important_info_contact_post_salmon_you }}

- {% else %} -

{{ mssgs.important_info_contact_post_not_salmon_you }}

- {% endif %} - {% else %} - {% if data.licensee.isSalmon %} -

{{ mssgs.important_info_contact_post_salmon_other }}

- {% else %} -

{{ mssgs.important_info_contact_post_not_salmon_other }}

- {% endif %} - {% endif %} +

{{ data.content }}

{% else %} {% if data.isJunior %}

{{ mssgs.important_info_contact_post_confirm_jr }}

diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/route.js b/packages/gafl-webapp-service/src/pages/contact/contact/route.js index 08d82c28c0..b0f26387a4 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/route.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/route.js @@ -11,6 +11,7 @@ import { mobilePhoneValidator } from '../../../processors/contact-validator.js' export const getData = async request => { const permission = await request.cache().helpers.transaction.getCurrentPermission() + const mssgs = request.i18n.getCatalog() // We need to have set the licence length, dob and start date here to determining the contact // messaging @@ -27,7 +28,13 @@ export const getData = async request => { } return { - isLicenceForYou: permission.isLicenceForYou, + title: permission.isLicenceForYou ? mssgs.important_info_contact_title_you : mssgs.important_info_contact_title_other, + emailText: permission.licensee.email ? mssgs.important_info_contact_item_email + ' ' + permission.licensee.email : mssgs.important_info_contact_item_email, + mobileText: permission.licensee.mobilePhone ? mssgs.important_info_contact_item_txt_value + permission.licensee.mobilePhone : mssgs.important_info_contact_item_txt, + postHint: permission.isLicenceForYou ? mssgs.important_info_contact_post_hint_you : mssgs.important_info_contact_post_hint_other, + content: permission.isLicenceForYou + ? (permission.licenceType === 'Salmon and sea trout' ? mssgs.important_info_contact_post_salmon_you : mssgs.important_info_contact_post_not_salmon_you) + : (permission.licenceType === 'Salmon and sea trout' ? mssgs.important_info_contact_post_salmon_other : mssgs.important_info_contact_post_not_salmon_other), licensee: permission.licensee, isPhysical: isPhysical(permission), isJunior: hasJunior(permission), From 3e689cdaa2468b28dbf7b48cace7787457a53b5d Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Wed, 15 Nov 2023 11:38:35 +0000 Subject: [PATCH 3/8] code smells --- package.json | 3 +- .../src/pages/contact/contact/route.js | 36 +++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index de33643c89..411b36cebb 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ ], "testEnvironment": "node", "testRunner": "jest-circus/runner", - "silent": true + "silent": false, + "verbose": true } } diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/route.js b/packages/gafl-webapp-service/src/pages/contact/contact/route.js index b0f26387a4..fc0bdc602b 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/route.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/route.js @@ -27,14 +27,36 @@ export const getData = async request => { throw new GetDataRedirect(LICENCE_LENGTH.uri) } + let title + let postHint + let content + if (permission.isLicenceForYou) { + title = mssgs.important_info_contact_title_you + postHint = mssgs.important_info_contact_post_hint_you + if (permission.licenceType === 'Salmon and sea trout') { + content = mssgs.important_info_contact_post_salmon_you + } else { + content = mssgs.important_info_contact_post_not_salmon_you + } + } else { + title = mssgs.important_info_contact_title_other + postHint = mssgs.important_info_contact_post_hint_other + if (permission.licenceType === 'Salmon and sea trout') { + content = mssgs.important_info_contact_post_salmon_other + } else { + content = mssgs.important_info_contact_post_not_salmon_other + } + } + + const emailValue = mssgs.important_info_contact_item_email + ' ' + permission.licensee.email + const mobileValue = mssgs.important_info_contact_item_txt_value + permission.licensee.mobilePhone + return { - title: permission.isLicenceForYou ? mssgs.important_info_contact_title_you : mssgs.important_info_contact_title_other, - emailText: permission.licensee.email ? mssgs.important_info_contact_item_email + ' ' + permission.licensee.email : mssgs.important_info_contact_item_email, - mobileText: permission.licensee.mobilePhone ? mssgs.important_info_contact_item_txt_value + permission.licensee.mobilePhone : mssgs.important_info_contact_item_txt, - postHint: permission.isLicenceForYou ? mssgs.important_info_contact_post_hint_you : mssgs.important_info_contact_post_hint_other, - content: permission.isLicenceForYou - ? (permission.licenceType === 'Salmon and sea trout' ? mssgs.important_info_contact_post_salmon_you : mssgs.important_info_contact_post_not_salmon_you) - : (permission.licenceType === 'Salmon and sea trout' ? mssgs.important_info_contact_post_salmon_other : mssgs.important_info_contact_post_not_salmon_other), + title, + postHint, + content, + emailText: permission.licensee.email ? emailValue : mssgs.important_info_contact_item_email, + mobileText: permission.licensee.mobilePhone ? mobileValue : mssgs.important_info_contact_item_txt, licensee: permission.licensee, isPhysical: isPhysical(permission), isJunior: hasJunior(permission), From b0d57103ae728493b619c2e0cd5b82c1871002e1 Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Wed, 15 Nov 2023 15:00:38 +0000 Subject: [PATCH 4/8] code smell change email value setup --- packages/gafl-webapp-service/src/locales/en.json | 1 + .../src/pages/contact/contact/__tests__/route.spec.js | 1 + packages/gafl-webapp-service/src/pages/contact/contact/route.js | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/gafl-webapp-service/src/locales/en.json b/packages/gafl-webapp-service/src/locales/en.json index e1107593af..0c85421da6 100644 --- a/packages/gafl-webapp-service/src/locales/en.json +++ b/packages/gafl-webapp-service/src/locales/en.json @@ -292,6 +292,7 @@ "important_info_contact_input_mobile_note": "UK mobile number", "important_info_contact_input_mobile": "UK mobile phone number", "important_info_contact_item_email": "Email", + "important_info_contact_item_email_value": "Email ", "important_info_contact_item_txt": "Text message", "important_info_contact_item_txt_value": "Text message to ", "important_info_contact_licence_needed": "The rod licence holder will need to confirm the licence number if asked by an enforcement officer.", diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js index a09d82be81..6d960ba7b4 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js @@ -46,6 +46,7 @@ describe('name > route', () => { important_info_contact_title_you: 'You title', important_info_contact_title_other: 'Other title', important_info_contact_item_email: 'Email', + important_info_contact_item_email_value: 'Email ', important_info_contact_item_txt_value: 'Text to ', important_info_contact_item_txt: 'Text', important_info_contact_post_hint_you: 'Post hint you', diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/route.js b/packages/gafl-webapp-service/src/pages/contact/contact/route.js index fc0bdc602b..bcbdddc334 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/route.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/route.js @@ -48,7 +48,7 @@ export const getData = async request => { } } - const emailValue = mssgs.important_info_contact_item_email + ' ' + permission.licensee.email + const emailValue = mssgs.important_info_contact_item_email_value + permission.licensee.email const mobileValue = mssgs.important_info_contact_item_txt_value + permission.licensee.mobilePhone return { From fcaf9b4f7876f90bf15b25c3fb29bb42d4e3e81b Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Thu, 16 Nov 2023 13:01:37 +0000 Subject: [PATCH 5/8] undo changes package.json --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 411b36cebb..de33643c89 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,6 @@ ], "testEnvironment": "node", "testRunner": "jest-circus/runner", - "silent": false, - "verbose": true + "silent": true } } From 759ac2bebc1597f04dd1f41370ae3a99af2ac453 Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Thu, 16 Nov 2023 14:37:33 +0000 Subject: [PATCH 6/8] fix lint --- .../src/pages/contact/contact/__tests__/route.spec.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js index 6d960ba7b4..63830d33c4 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js @@ -95,10 +95,13 @@ describe('name > route', () => { [true, 'Trout and coarse', 'Not salmon you'], [false, 'Salmon and sea trout', 'Salmon other'], [false, 'Trout and coarse', 'Not salmon other'] - ])('content has correct value depending on isLicenceForYou is %s and licenceType is %s', async (isLicenceForYou, licenceType, expected) => { - const result = await getData(getMockRequest({ isLicenceForYou, licenceType })) - expect(result.content).toBe(expected) - }) + ])( + 'content has correct value depending on isLicenceForYou is %s and licenceType is %s', + async (isLicenceForYou, licenceType, expected) => { + const result = await getData(getMockRequest({ isLicenceForYou, licenceType })) + expect(result.content).toBe(expected) + } + ) it.each([ [true, true], From 4003e94d5ab06f8cf57f31d1fdb2e99517ae051a Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Thu, 16 Nov 2023 17:06:57 +0000 Subject: [PATCH 7/8] refactor route and fix spelling issue --- .../gafl-webapp-service/src/locales/en.json | 4 +- .../contact/contact/__tests__/route.spec.js | 4 +- .../src/pages/contact/contact/route.js | 49 ++++++++----------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/packages/gafl-webapp-service/src/locales/en.json b/packages/gafl-webapp-service/src/locales/en.json index 0c85421da6..53afbbc1ea 100644 --- a/packages/gafl-webapp-service/src/locales/en.json +++ b/packages/gafl-webapp-service/src/locales/en.json @@ -285,12 +285,12 @@ "identify_title": "Renew your rod fishing licence?", "important_info_contact_error_choose": "Choose how we should contact the licence holder", "important_info_contact_error_email": "Enter an email address in the correct format", - "important_info_contact_error_mobile": "Enter a UK mobile phone number", + "important_info_contact_error_mobile": "Enter a UK mobile number", "important_info_contact_input_email_hint": "For example name@example.com", "important_info_contact_input_email": "Email address", "important_info_contact_input_mobile_hint": "For example 07700 900 900", "important_info_contact_input_mobile_note": "UK mobile number", - "important_info_contact_input_mobile": "UK mobile phone number", + "important_info_contact_input_mobile": "UK mobile number", "important_info_contact_item_email": "Email", "important_info_contact_item_email_value": "Email ", "important_info_contact_item_txt": "Text message", diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js index 63830d33c4..1f2946a0bc 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/route.spec.js @@ -69,7 +69,7 @@ describe('name > route', () => { it.each([ ['test@email.com', 'Email test@email.com'], [null, 'Email'] - ])('emailText has correct value depedning on if permission has an email', async (email, expected) => { + ])('emailText has correct value depending on if permission has an email', async (email, expected) => { const result = await getData(getMockRequest({ email })) expect(result.emailText).toBe(expected) }) @@ -77,7 +77,7 @@ describe('name > route', () => { it.each([ ['07123456789', 'Text to 07123456789'], [null, 'Text'] - ])('mobileText has correct value depedning on if permission has a phone number', async (mobilePhone, expected) => { + ])('mobileText has correct value depending on if permission has a phone number', async (mobilePhone, expected) => { const result = await getData(getMockRequest({ mobilePhone })) expect(result.mobileText).toBe(expected) }) diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/route.js b/packages/gafl-webapp-service/src/pages/contact/contact/route.js index bcbdddc334..101e5ca48d 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/route.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/route.js @@ -27,36 +27,12 @@ export const getData = async request => { throw new GetDataRedirect(LICENCE_LENGTH.uri) } - let title - let postHint - let content - if (permission.isLicenceForYou) { - title = mssgs.important_info_contact_title_you - postHint = mssgs.important_info_contact_post_hint_you - if (permission.licenceType === 'Salmon and sea trout') { - content = mssgs.important_info_contact_post_salmon_you - } else { - content = mssgs.important_info_contact_post_not_salmon_you - } - } else { - title = mssgs.important_info_contact_title_other - postHint = mssgs.important_info_contact_post_hint_other - if (permission.licenceType === 'Salmon and sea trout') { - content = mssgs.important_info_contact_post_salmon_other - } else { - content = mssgs.important_info_contact_post_not_salmon_other - } - } - - const emailValue = mssgs.important_info_contact_item_email_value + permission.licensee.email - const mobileValue = mssgs.important_info_contact_item_txt_value + permission.licensee.mobilePhone - return { - title, - postHint, - content, - emailText: permission.licensee.email ? emailValue : mssgs.important_info_contact_item_email, - mobileText: permission.licensee.mobilePhone ? mobileValue : mssgs.important_info_contact_item_txt, + title: getTitle(permission, mssgs), + postHint: getPostHint(permission, mssgs), + content: getContent(permission, mssgs), + emailText: getEmailText(permission, mssgs), + mobileText: getMobileText(permission, mssgs), licensee: permission.licensee, isPhysical: isPhysical(permission), isJunior: hasJunior(permission), @@ -64,6 +40,21 @@ export const getData = async request => { } } +const getTitle = (permission, messages) => permission.isLicenceForYou ? messages.important_info_contact_title_you : messages.important_info_contact_title_other + +const getPostHint = (permission, messages) => permission.isLicenceForYou ? messages.important_info_contact_post_hint_you : messages.important_info_contact_post_hint_other + +const getContent = (permission, messages) => { + if (permission.licenceType === 'Salmon and sea trout') { + return permission.isLicenceForYou ? messages.important_info_contact_post_salmon_you : messages.important_info_contact_post_salmon_other + } + return permission.isLicenceForYou ? messages.important_info_contact_post_not_salmon_you : messages.important_info_contact_post_not_salmon_other +} + +const getMobileText = (permission, messages) => permission.licensee.mobilePhone ? `${messages.important_info_contact_item_txt_value}${permission.licensee.mobilePhone}` : messages.important_info_contact_item_txt + +const getEmailText = (permission, messages) => permission.licensee.email ? `${messages.important_info_contact_item_email_value}${permission.licensee.email}` : messages.important_info_contact_item_email + export const validator = Joi.object({ 'how-contacted': Joi.string().valid('email', 'text', 'none').required(), email: Joi.alternatives().conditional('how-contacted', { From 9d6199e1d1f41fb4b1f02ca14e5d998ee1c4bb07 Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Thu, 16 Nov 2023 17:15:42 +0000 Subject: [PATCH 8/8] code smell --- .../src/pages/contact/contact/route.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/route.js b/packages/gafl-webapp-service/src/pages/contact/contact/route.js index 101e5ca48d..912bc77093 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/route.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/route.js @@ -40,9 +40,15 @@ export const getData = async request => { } } -const getTitle = (permission, messages) => permission.isLicenceForYou ? messages.important_info_contact_title_you : messages.important_info_contact_title_other +const getTitle = (permission, messages) => + permission.isLicenceForYou + ? messages.important_info_contact_title_you + : messages.important_info_contact_title_other -const getPostHint = (permission, messages) => permission.isLicenceForYou ? messages.important_info_contact_post_hint_you : messages.important_info_contact_post_hint_other +const getPostHint = (permission, messages) => + permission.isLicenceForYou + ? messages.important_info_contact_post_hint_you + : messages.important_info_contact_post_hint_other const getContent = (permission, messages) => { if (permission.licenceType === 'Salmon and sea trout') { @@ -51,9 +57,15 @@ const getContent = (permission, messages) => { return permission.isLicenceForYou ? messages.important_info_contact_post_not_salmon_you : messages.important_info_contact_post_not_salmon_other } -const getMobileText = (permission, messages) => permission.licensee.mobilePhone ? `${messages.important_info_contact_item_txt_value}${permission.licensee.mobilePhone}` : messages.important_info_contact_item_txt +const getMobileText = (permission, messages) => + permission.licensee.mobilePhone + ? `${messages.important_info_contact_item_txt_value}${permission.licensee.mobilePhone}` + : messages.important_info_contact_item_txt -const getEmailText = (permission, messages) => permission.licensee.email ? `${messages.important_info_contact_item_email_value}${permission.licensee.email}` : messages.important_info_contact_item_email +const getEmailText = (permission, messages) => + permission.licensee.email + ? `${messages.important_info_contact_item_email_value}${permission.licensee.email}` + : messages.important_info_contact_item_email export const validator = Joi.object({ 'how-contacted': Joi.string().valid('email', 'text', 'none').required(),