From 40a9f02087c0ff91ea6e4185d0ddaad78aa4cc92 Mon Sep 17 00:00:00 2001 From: omega1119 Date: Thu, 21 Nov 2024 15:48:38 +0000 Subject: [PATCH] feat(AHWR-261): Only CC sent via SFD proxy route for Claim emails from ahwr-application (#73) * feat/fix-tests updated tests for crn and sbi in SFD tests * feat(AHWR-202): version bump * feat(AHWR-202): remove comments --- app/email/notify-send.js | 13 ++++++++----- app/email/sfd-client.js | 6 +++--- app/messaging/submit-sfd-schema.js | 6 +++--- package.json | 2 +- test/unit/email/sfd-client.test.js | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/email/notify-send.js b/app/email/notify-send.js index 4ce1ef5..dc75ae2 100644 --- a/app/email/notify-send.js +++ b/app/email/notify-send.js @@ -19,15 +19,18 @@ const send = async (templateId, email, personalisation) => { // sbi and crn were added into personalisation object to get them into here without changing upstream method signatures // for the time being we'll pull them out here and send into SFD route where they are needed, and make sure they don't // go into the old route where they aren't needed - const { sbi, crn } = personalisation.personalisation - delete personalisation.personalisation.crn - delete personalisation.personalisation.sbi + const { crn, sbi, ...filteredPersonalisation } = personalisation.personalisation + const copyOfPersonalisation = { + ...personalisation, + personalisation: filteredPersonalisation + } + try { if (sfdMessage.enabled) { return sendSFDEmail( templateId, email, - personalisation, + copyOfPersonalisation, crn, sbi ) @@ -35,7 +38,7 @@ const send = async (templateId, email, personalisation) => { return notifyClient.sendEmail( templateId, email, - personalisation + copyOfPersonalisation ) } catch (error) { throw Error(error) diff --git a/app/email/sfd-client.js b/app/email/sfd-client.js index b35f9e9..445cfea 100644 --- a/app/email/sfd-client.js +++ b/app/email/sfd-client.js @@ -1,6 +1,6 @@ const sendMessage = require('../messaging/send-message') const { sfdRequestMsgType, messageQueueConfig: { sfdMessageQueue } } = require('../config') -const validateSFDClaim = require('../messaging/submit-sfd-schema') +const validateSFDSchema = require('../messaging/submit-sfd-schema') const states = require('../messaging/states') const sendSFDEmail = async (templateId, email, emailInput, crn, sbi) => { @@ -17,11 +17,11 @@ const sendSFDEmail = async (templateId, email, emailInput, crn, sbi) => { dateTime: new Date().toISOString() } - if (validateSFDClaim(sfdMessage)) { + if (validateSFDSchema(sfdMessage)) { return sendMessage(sfdMessage, sfdRequestMsgType, sfdMessageQueue) } else { // Check this because I am not sure why we would still send a request here. Proxy won't handle this - return sendMessage({ applicationState: states.failed }, sfdRequestMsgType, sfdMessageQueue, { templateId }) + return sendMessage({ sfdMessage: states.failed }, sfdRequestMsgType, sfdMessageQueue, { templateId }) } } diff --git a/app/messaging/submit-sfd-schema.js b/app/messaging/submit-sfd-schema.js index addef64..8b0ea60 100644 --- a/app/messaging/submit-sfd-schema.js +++ b/app/messaging/submit-sfd-schema.js @@ -20,14 +20,14 @@ const submitSFDSchema = joi.object({ dateTime: joi.date().required() }) -const validateSFDClaim = (event) => { +const validateSFDSchema = (event) => { const validate = submitSFDSchema.validate(event) if (validate.error) { - console.log('Submit claim validation error:', util.inspect(validate.error, false, null, true)) + console.log('Submit SFD message validation error:', util.inspect(validate.error, false, null, true)) return false } return true } -module.exports = validateSFDClaim +module.exports = validateSFDSchema diff --git a/package.json b/package.json index b3a6e03..f7fed93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ffc-ahwr-document-generator", - "version": "0.13.26", + "version": "0.13.27", "description": "Generate and send documents for AHWR", "homepage": "https://github.com/DEFRA/ffc-ahwr-document-generator", "main": "app/index.js", diff --git a/test/unit/email/sfd-client.test.js b/test/unit/email/sfd-client.test.js index 122934d..73c8b45 100644 --- a/test/unit/email/sfd-client.test.js +++ b/test/unit/email/sfd-client.test.js @@ -45,7 +45,7 @@ describe('sendSFDEmail', () => { expect(sfdMessageSend).toHaveBeenCalledTimes(1) expect(sfdMessageSend).toHaveBeenCalledWith({ - applicationState: 'failed' + sfdMessage: 'failed' }, 'uk.gov.ffc.ahwr.sfd.request', expect.anything(), { templateId: '99ef9794-67eb-4f18-bb38-541f30f955f8' }) })