Skip to content

Commit

Permalink
add to use licensee instead paylaod if payload is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottDormand96 committed Nov 28, 2023
1 parent 8714d52 commit 67e1dd4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ describe('contact > update-transaction', () => {
{ email, mobilePhone },
['[email protected]', 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 = []) => {
Expand Down Expand Up @@ -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 = []) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -41,15 +44,15 @@ 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':
return {
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

{{ govukNotificationBanner({
html: bannerHtml,
titleText: mssgs.price_increase_notification_label
titleText: mssgs.notification_label
}) }}
{% endmacro %}

0 comments on commit 67e1dd4

Please sign in to comment.