-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3574 from bcgov/NDT-514-bug-budget-details-number…
…s-are-inconsistent-between-application-and-template feat: email notification on failed template read
- Loading branch information
Showing
14 changed files
with
439 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/backend/lib/emails/templates/notifyFailedReadOfTemplateData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import getConfig from 'next/config'; | ||
import { | ||
EmailTemplate, | ||
EmailTemplateProvider, | ||
} from '../handleEmailNotification'; | ||
|
||
interface EmailTemplateParams { | ||
templateNumber: string; | ||
uuid: string; | ||
organizationName: string | undefined; | ||
projectTitle: string | undefined; | ||
uploadedAt: string | undefined; | ||
} | ||
|
||
const notifyFailedReadOfTemplateData: EmailTemplateProvider = ( | ||
applicationId: string, | ||
url: string, | ||
initiator, | ||
params: EmailTemplateParams | ||
): EmailTemplate => { | ||
const namespace = getConfig()?.publicRuntimeConfig?.OPENSHIFT_APP_NAMESPACE; | ||
let env = 'Dev'; | ||
if (namespace?.endsWith('-prod')) { | ||
env = 'Prod'; | ||
} else if (namespace?.endsWith('-test')) { | ||
env = 'Test'; | ||
} | ||
|
||
return { | ||
emailTo: [111, 112, 113, 114, 115], | ||
emailCC: [], | ||
tag: 'failed-read-of-template-data', | ||
subject: `Template ${params.templateNumber} - Failed Response`, | ||
body: ` | ||
<p> | ||
The following template upload by an applicant had a failed response at ${params.uploadedAt}: | ||
</p> | ||
<ul> | ||
<li>Environment: ${env}</li> | ||
<li>File UUID: ${params.uuid}</li> | ||
<li>Template Number: ${params.templateNumber}</li> | ||
<li>Application ID: ${applicationId}</li> | ||
</ul> | ||
`, | ||
}; | ||
}; | ||
|
||
export default notifyFailedReadOfTemplateData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/tests/backend/lib/emails/templates/notifyFailedReadOfTemplateData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import notifyFailedReadOfTemplateData from 'backend/lib/emails/templates/notifyFailedReadOfTemplateData'; | ||
|
||
describe('notifyApplicationSubmission template', () => { | ||
it('should return an email template with correct properties', () => { | ||
const applicationId = '1'; | ||
const url = 'http://mock_host.ca'; | ||
|
||
const emailTemplate = notifyFailedReadOfTemplateData( | ||
applicationId, | ||
url, | ||
{}, | ||
{ templateNumber: 1 } | ||
); | ||
|
||
expect(emailTemplate).toEqual( | ||
expect.objectContaining({ | ||
emailTo: [111, 112, 113, 114, 115], | ||
emailCC: [], | ||
tag: 'failed-read-of-template-data', | ||
subject: 'Template 1 - Failed Response', | ||
body: expect.anything(), | ||
}) | ||
); | ||
}); | ||
|
||
it('should format parameters in body', () => { | ||
const applicationId = '321'; | ||
const url = 'http://mock_host.ca'; | ||
|
||
const emailTemplate = notifyFailedReadOfTemplateData( | ||
applicationId, | ||
url, | ||
{}, | ||
{ uuid: '123', templateNumber: 1, uploadedAt: 'asdf' } | ||
); | ||
|
||
expect(emailTemplate.body).toContain(`Environment: Dev`); | ||
expect(emailTemplate.body).toContain(`Application ID: 321`); | ||
expect(emailTemplate.body).toContain(`File UUID: 123`); | ||
expect(emailTemplate.body).toContain(`Template Number: 1`); | ||
expect(emailTemplate.body).toContain(`a failed response at asdf`); | ||
}); | ||
}); |
Oops, something went wrong.