-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
form submission: error handling and logging for email notifications #114
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,41 @@ import config from '../../config/index.js' | |
|
||
vi.mock('../../src/utils/mailClient.js') | ||
|
||
describe('Check answers controller', () => { | ||
function makeRequest () { | ||
return { | ||
sessionModel: { | ||
get: vi.fn().mockImplementation((key) => { | ||
const values = { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
lpa: 'LPA', | ||
dataset: 'Dataset', | ||
'documentation-url': 'Documentation URL', | ||
'endpoint-url': 'Endpoint URL' | ||
} | ||
return values[key] | ||
}) | ||
} | ||
} | ||
} | ||
|
||
describe('Handle email notification handlers', async () => { | ||
const CheckAnswersController = await vi.importActual('../../src/controllers/CheckAnswersController.js') | ||
const sendEmailMock = vi.fn(() => Promise.reject(new Error('something went wrong'))) | ||
notifyClient.sendEmail = sendEmailMock | ||
|
||
const controller = new CheckAnswersController.default({ route: '/dataset' }) | ||
const req = makeRequest() | ||
const res = {} | ||
const next = vi.fn() | ||
|
||
it('should reuturn list of errors when failed to send email', async () => { | ||
const result = await controller.sendEmails(req, res, next) | ||
expect(result.errors.length).toBe(2) | ||
}) | ||
}) | ||
|
||
describe('Check answers controller', async () => { | ||
let CheckAnswersController | ||
let checkAnswersController | ||
let sendEmailMock | ||
|
@@ -22,57 +56,33 @@ describe('Check answers controller', () => { | |
}) | ||
|
||
describe('send emails', () => { | ||
it('should get the values from the session model and then send the request and acknowledgement emails', () => { | ||
it('should get the values from the session model and then send the request and acknowledgement emails', async () => { | ||
// Mock req, res, next | ||
const req = { | ||
sessionModel: { | ||
get: vi.fn().mockImplementation((key) => { | ||
const values = { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
lpa: 'LPA', | ||
dataset: 'Dataset', | ||
'documentation-url': 'Documentation URL', | ||
'endpoint-url': 'Endpoint URL' | ||
} | ||
return values[key] | ||
}) | ||
} | ||
} | ||
|
||
const req = makeRequest() | ||
const res = {} | ||
const next = vi.fn() | ||
|
||
checkAnswersController.sendEmails(req, res, next) | ||
await checkAnswersController.sendEmails(req, res, next) | ||
|
||
const personalisation = { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
organisation: 'LPA', | ||
dataset: 'Dataset', | ||
'documentation-url': 'Documentation URL', | ||
endpoint: 'Endpoint URL' | ||
} | ||
|
||
expect(sendEmailMock).toHaveBeenCalledWith( | ||
config.email.templates.RequestTemplateId, | ||
config.email.dataManagementEmail, | ||
{ | ||
personalisation: { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
organisation: 'LPA', | ||
dataset: 'Dataset', | ||
'documentation-url': 'Documentation URL', | ||
endpoint: 'Endpoint URL' | ||
} | ||
} | ||
{ personalisation } | ||
) | ||
|
||
expect(sendEmailMock).toHaveBeenCalledWith( | ||
config.email.templates.AcknowledgementTemplateId, | ||
'[email protected]', | ||
{ | ||
personalisation: { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
organisation: 'LPA', | ||
endpoint: 'Endpoint URL', | ||
'documentation-url': 'Documentation URL', | ||
dataset: 'Dataset' | ||
} | ||
} | ||
{ personalisation } | ||
) | ||
}) | ||
}) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be addressed in a later ticket, but as we have now merged the repos we have access to a logger. I'll add a tech debt ticket to update all console messages in the submit part of this repo to use the logger instead