From 0243f5dfc344157ed55913434b200e19b51198a4 Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Mon, 27 Nov 2023 15:23:08 +0000 Subject: [PATCH] move check outside njk and use constants for checking preferred method --- .../contact/contact/__tests__/route.spec.js | 18 ++++++++++++++++++ .../src/pages/contact/contact/contact.njk | 4 ++-- .../src/pages/contact/contact/route.js | 7 +++++-- 3 files changed, 25 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 47b1bdd4c7..3d33caba8d 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 @@ -87,6 +87,24 @@ describe('name > route', () => { expect(result.mobileText).toBe('Text to 07123456789') }) + it.each([ + [false, 'Text'], + [true, 'Email'] + ])('emailConfirmation is %s when preferredMethodOfConfirmation is %s', async (expected, method) => { + const licensee = { birthDate: 'birthDate', preferredMethodOfConfirmation: method, email: 'test@email.com' } + const result = await getData(getMockRequest({ licensee })) + expect(result.emailConfirmation).toBe(expected) + }) + + it.each([ + [false, 'Email'], + [true, 'Text'] + ])('mobileConfirmation is %s when preferredMethodOfConfirmation is %s', async (expected, method) => { + const licensee = { birthDate: 'birthDate', preferredMethodOfConfirmation: method, email: 'test@email.com' } + const result = await getData(getMockRequest({ licensee })) + expect(result.mobileConfirmation).toBe(expected) + }) + it.each([ [true, 'Post hint you'], [false, 'Post hint other'] 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 bda48846c3..c86200cab4 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk +++ b/packages/gafl-webapp-service/src/pages/contact/contact/contact.njk @@ -93,7 +93,7 @@ {% endset -%} {% set itemsArray = [] %} -{% if data.licensee.preferredMethodOfConfirmation === 'Email' %} +{% if data.emailConfirmation %} {% set itemsArray = (itemsArray.push( { value: "email", @@ -114,7 +114,7 @@ %} {% endif %} -{% if data.licensee.preferredMethodOfConfirmation === 'Text' %} +{% if data.mobileConfirmation %} {% set itemsArray = (itemsArray.push( { value: "text", 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 25d73885e6..0d4bb70798 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/route.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/route.js @@ -7,6 +7,7 @@ import { isPhysical } from '../../../processors/licence-type-display.js' import { hasJunior } from '../../../processors/concession-helper.js' import { nextPage } from '../../../routes/next-page.js' import { mobilePhoneValidator } from '../../../processors/contact-validator.js' +import { HOW_CONTACTED } from '../../../processors/mapping-constants.js' export const getData = async request => { const permission = await request.cache().helpers.transaction.getCurrentPermission() @@ -30,7 +31,9 @@ export const getData = async request => { title: getTitle(permission, mssgs), postHint: getPostHint(permission, mssgs), content: getContent(permission, mssgs), + emailConfirmation: permission.licensee.preferredMethodOfConfirmation === HOW_CONTACTED.email, emailText: getEmailText(permission, mssgs), + mobileConfirmation: permission.licensee.preferredMethodOfConfirmation === HOW_CONTACTED.text, mobileText: getMobileText(permission, mssgs), licensee: permission.licensee, isPhysical: isPhysical(permission), @@ -56,12 +59,12 @@ const getContent = (permission, messages) => { } const getMobileText = (permission, messages) => - permission.licensee.preferredMethodOfConfirmation === 'Text' + permission.licensee.preferredMethodOfConfirmation === HOW_CONTACTED.text ? `${messages.important_info_contact_item_txt_value}${permission.licensee.mobilePhone}` : messages.important_info_contact_item_txt const getEmailText = (permission, messages) => - permission.licensee.preferredMethodOfConfirmation === 'Email' + permission.licensee.preferredMethodOfConfirmation === HOW_CONTACTED.email ? `${messages.important_info_contact_item_email_value}${permission.licensee.email}` : messages.important_info_contact_item_email