-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rosado/missing-deps
- Loading branch information
Showing
3 changed files
with
108 additions
and
74 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
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 } | ||
) | ||
}) | ||
}) | ||
|