Skip to content

Commit a2c989d

Browse files
authored
Merge pull request #56 from DEFRA/fix/DF-330-missing-guidance
Uses placeholder text if submission guidance is not yet defined
2 parents 8af48a6 + 8bd0a71 commit a2c989d

4 files changed

Lines changed: 26 additions & 25 deletions

File tree

src/service/mappers/user-confirmation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { escapeMarkdown } from '@defra/forms-engine-plugin/engine/components/hel
22

33
import { format as dateFormat } from '~/src/helpers/date.js'
44

5+
const submisionGuidancePlaceholder =
6+
"Define this text in the 'What happens next' section of the form overview"
7+
58
/**
69
* @param {string} formName
710
* @param {Date} submissionDate
@@ -30,7 +33,7 @@ export function getUserConfirmationEmailBody(
3033
We received your form submission for ‘${formName}’ on ${formattedSubmissionDate}.
3134
3235
## What happens next
33-
${submissionGuidance}
36+
${submissionGuidance ?? submisionGuidancePlaceholder}
3437
3538
## Get help
3639
${contactDetails}Do not reply to this emall. We do not monitor reples to this email address.

src/service/mappers/user-confirmation.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@ Some submission guidance
2222
## Get help
2323
Do not reply to this emall. We do not monitor reples to this email address.
2424
25+
From Defra
26+
`
27+
)
28+
})
29+
30+
test('should handle missing submission guidance', () => {
31+
const formName = 'My Form Name'
32+
const submissionDate = new Date('2025-11-04T14:21:35+00:00')
33+
const metadata = buildMetaData()
34+
expect(
35+
getUserConfirmationEmailBody(formName, submissionDate, metadata)
36+
).toBe(
37+
`
38+
# We have your form
39+
We received your form submission for ‘My Form Name’ on 2:21pm on Tuesday 4 November 2025.
40+
41+
## What happens next
42+
Define this text in the 'What happens next' section of the form overview
43+
44+
## Get help
45+
Do not reply to this emall. We do not monitor reples to this email address.
46+
2547
From Defra
2648
`
2749
)

src/service/notify.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ export async function sendUserConfirmationEmail(formSubmissionMessage) {
160160

161161
logger.info(logTags, 'Sending user confirmation email')
162162

163-
if (!metadata.submissionGuidance) {
164-
throw new Error(`Missing submission guidance for form id ${formId}`)
165-
}
166-
167163
try {
168164
// Send confirmation email
169165
await sendNotification({

src/service/notify.test.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -698,26 +698,6 @@ describe('notify', () => {
698698
})
699699
})
700700

701-
it('should throw if confirmation email has no submission guidance set', async () => {
702-
jest.mocked(getFormDefinition).mockResolvedValueOnce(baseDefinition)
703-
jest.mocked(getFormMetadata).mockResolvedValueOnce(
704-
buildMetaData({
705-
submissionGuidance: undefined
706-
})
707-
)
708-
const formAdapterMessageWithUserEmail = structuredClone(
709-
formAdapterSubmissionMessage
710-
)
711-
formAdapterMessageWithUserEmail.meta.custom = {
712-
userConfirmationEmail: 'my-email@test.com'
713-
}
714-
await expect(() =>
715-
sendNotifyEmails(formAdapterMessageWithUserEmail)
716-
).rejects.toThrow(
717-
'Missing submission guidance for form id 68a8b0449ab460290c28940a'
718-
)
719-
})
720-
721701
it('confirmation email should handle and throw errors', async () => {
722702
const err = new Error('Upstream failure')
723703
jest.mocked(getFormDefinition).mockResolvedValueOnce(baseDefinition)

0 commit comments

Comments
 (0)