Skip to content

Commit

Permalink
move check outside njk and use constants for checking preferred method
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottDormand96 committed Nov 27, 2023
1 parent 230852a commit 0243f5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]' }
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: '[email protected]' }
const result = await getData(getMockRequest({ licensee }))
expect(result.mobileConfirmation).toBe(expected)
})

it.each([
[true, 'Post hint you'],
[false, 'Post hint other']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
{% endset -%}

{% set itemsArray = [] %}
{% if data.licensee.preferredMethodOfConfirmation === 'Email' %}
{% if data.emailConfirmation %}
{% set itemsArray = (itemsArray.push(
{
value: "email",
Expand All @@ -114,7 +114,7 @@
%}
{% endif %}

{% if data.licensee.preferredMethodOfConfirmation === 'Text' %}
{% if data.mobileConfirmation %}
{% set itemsArray = (itemsArray.push(
{
value: "text",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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),
Expand All @@ -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

Expand Down

0 comments on commit 0243f5d

Please sign in to comment.