From 67e1dd4f423661497af03c829743df10aacd1013 Mon Sep 17 00:00:00 2001 From: ScottDormand96 Date: Tue, 28 Nov 2023 14:26:22 +0000 Subject: [PATCH] add to use licensee instead paylaod if payload is undefined --- .../contact/__tests__/update-transaction.spec.js | 8 ++++++-- .../pages/contact/contact/update-transaction.js | 15 +++++++++------ .../src/pages/macros/notification-banner.njk | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/update-transaction.spec.js b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/update-transaction.spec.js index c330a70415..d1cb1c0951 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/update-transaction.spec.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/__tests__/update-transaction.spec.js @@ -49,7 +49,9 @@ describe('contact > update-transaction', () => { { email, mobilePhone }, ['someone@example.com', mobilePhone], [{ email }] - ] + ], + ['text', 'Text', 'set mobilePhone based off licensee when payload undefined', { mobilePhone }, [], [{ mobilePhone }]], + ['email', 'Email', 'set email based off licensee when payload undefined', { email }, [], [{ email }]] ])( 'when how-contacted is %s, should set preferredMethodOfReminder to "%s" and %s', async (howContacted, preferredMethod, _desc, expectedLicencee = {}, pagePermissionArgs = [], transactionPermissionArgs = []) => { @@ -96,7 +98,9 @@ describe('contact > update-transaction', () => { { email, mobilePhone }, [null, mobilePhone], [{ preferredMethodOfNewsletter: 'Email', email }] - ] + ], + ['text', 'Text', 'set mobilePhone based off licensee when payload undefined', { mobilePhone }, [], [{ mobilePhone }]], + ['email', 'Email', 'set email based off licensee when payload undefined', { email }, [], [{ email }]] ])( 'when how-contacted is %s, should set preferredMethodOfReminder and preferredMethodOfConfirmation to "%s" and %s', async (howContacted, preferredMethod, _desc, expectedLicencee = {}, pagePermissionArgs = [], transactionPermissionArgs = []) => { diff --git a/packages/gafl-webapp-service/src/pages/contact/contact/update-transaction.js b/packages/gafl-webapp-service/src/pages/contact/contact/update-transaction.js index 863a2628e4..7d16b43ad1 100644 --- a/packages/gafl-webapp-service/src/pages/contact/contact/update-transaction.js +++ b/packages/gafl-webapp-service/src/pages/contact/contact/update-transaction.js @@ -6,26 +6,29 @@ export default async request => { const { payload } = await request.cache().helpers.page.getCurrentPermission(CONTACT.page) const permission = await request.cache().helpers.transaction.getCurrentPermission() + console.log(permission) + permission.licensee = { preferredMethodOfNewsletter: HOW_CONTACTED.none, ...permission.licensee, - ...(isPhysical(permission) ? getPhysicalReminders(payload) : getDigitalConfirmationsAndReminders(permission.licensee, payload)) + ...(isPhysical(permission) ? getPhysicalReminders(permission.licensee, payload) : getDigitalConfirmationsAndReminders(permission.licensee, payload)) } await request.cache().helpers.transaction.setCurrentPermission(permission) } -const getPhysicalReminders = payload => { +const getPhysicalReminders = (licensee, payload) => { + console.log('HIT') switch (payload['how-contacted']) { case 'email': return { - email: payload.email, + email: payload.email ? payload.email : licensee.email, preferredMethodOfReminder: HOW_CONTACTED.email } case 'text': return { preferredMethodOfReminder: HOW_CONTACTED.text, - mobilePhone: payload.text + mobilePhone: payload.text ? payload.text : licensee.mobilePhone } default: return { @@ -41,7 +44,7 @@ const getDigitalConfirmationsAndReminders = (licensee, payload) => { postalFulfilment: false, preferredMethodOfConfirmation: HOW_CONTACTED.email, preferredMethodOfReminder: HOW_CONTACTED.email, - email: payload.email, + email: payload.email ? payload.email : licensee.email, mobilePhone: null } case 'text': @@ -49,7 +52,7 @@ const getDigitalConfirmationsAndReminders = (licensee, payload) => { postalFulfilment: false, preferredMethodOfConfirmation: HOW_CONTACTED.text, preferredMethodOfReminder: HOW_CONTACTED.text, - mobilePhone: payload.text, + mobilePhone: payload.text ? payload.text : licensee.mobilePhone, email: licensee.preferredMethodOfNewsletter === HOW_CONTACTED.email ? licensee.email : null } default: diff --git a/packages/gafl-webapp-service/src/pages/macros/notification-banner.njk b/packages/gafl-webapp-service/src/pages/macros/notification-banner.njk index b2a01decdd..72b52a0dec 100644 --- a/packages/gafl-webapp-service/src/pages/macros/notification-banner.njk +++ b/packages/gafl-webapp-service/src/pages/macros/notification-banner.njk @@ -12,6 +12,6 @@ {{ govukNotificationBanner({ html: bannerHtml, - titleText: mssgs.price_increase_notification_label + titleText: mssgs.notification_label }) }} {% endmacro %}