Skip to content

Commit

Permalink
feat(AHWR-261): Only CC sent via SFD proxy route for Claim emails fro…
Browse files Browse the repository at this point in the history
…m 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
  • Loading branch information
omega1119 authored Nov 21, 2024
1 parent bcb077f commit 40a9f02
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
13 changes: 8 additions & 5 deletions app/email/notify-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,26 @@ 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
)
}
return notifyClient.sendEmail(
templateId,
email,
personalisation
copyOfPersonalisation
)
} catch (error) {
throw Error(error)
Expand Down
6 changes: 3 additions & 3 deletions app/email/sfd-client.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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 })
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/messaging/submit-sfd-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/email/sfd-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
})
Expand Down

0 comments on commit 40a9f02

Please sign in to comment.