-
Notifications
You must be signed in to change notification settings - Fork 14
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 #1091 from gchq/feature/BAI-1174-emails-sent-inclu…
…de-todo-in-the-url-fields-for-the-buttons-e.g-reviews Add urls to emails
- Loading branch information
Showing
4 changed files
with
99 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
const config = { | ||
app: { | ||
protocol: '', | ||
host: '', | ||
port: 3000, | ||
}, | ||
connectors: { | ||
authentication: { | ||
kind: 'silly', | ||
|
24 changes: 22 additions & 2 deletions
24
backend/test/services/smtp/__snapshots__/smtp.spec.ts.snap
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 |
---|---|---|
@@ -1,8 +1,28 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`services > smtp > smtp > that an email is sent after a response for a an access request review 1`] = `undefined`; | ||
exports[`services > smtp > smtp > that an email is sent after a response for a an access request review 1`] = ` | ||
[ | ||
{ | ||
"from": "\\"Bailo 📝\\" <[email protected]>", | ||
"html": "html", | ||
"subject": "subject", | ||
"text": "text", | ||
"to": "[email protected]", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`services > smtp > smtp > that an email is sent after a response for a release review 1`] = `undefined`; | ||
exports[`services > smtp > smtp > that an email is sent after a response for a release review 1`] = ` | ||
[ | ||
{ | ||
"from": "\\"Bailo 📝\\" <[email protected]>", | ||
"html": "html", | ||
"subject": "subject", | ||
"text": "text", | ||
"to": "[email protected]", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`services > smtp > smtp > that an email is sent for Access Request Reviews 1`] = ` | ||
[ | ||
|
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 |
---|---|---|
|
@@ -71,7 +71,7 @@ const emailBuilderMock = vi.hoisted(() => ({ | |
vi.mock('../../../src/services/v2/smtp/emailBuilder.js', async () => emailBuilderMock) | ||
|
||
describe('services > smtp > smtp', () => { | ||
const review = new Review({ role: 'owner' }) | ||
const review = new Review({ role: 'owner', responses: [{ decision: 'approve' }] }) | ||
const release = new Release({ modelId: 'testmodel-123', semver: '1.2.3', createdBy: 'user:user' }) | ||
const access = new AccessRequest({ metadata: { overview: { entities: ['user:user'] } } }) | ||
|
||
|
@@ -115,6 +115,44 @@ describe('services > smtp > smtp', () => { | |
expect(transporterMock.sendMail).not.toBeCalled() | ||
}) | ||
|
||
test('that an email is not sent after a response for a release review if disabled in config', async () => { | ||
vi.spyOn(config, 'smtp', 'get').mockReturnValue({ | ||
enabled: false, | ||
connection: { | ||
host: 'localhost', | ||
port: 1025, | ||
secure: false, | ||
auth: { user: '', pass: '' }, | ||
tls: { | ||
rejectUnauthorized: false, | ||
}, | ||
}, | ||
from: '"Bailo 📝" <[email protected]>', | ||
}) | ||
await notifyReviewResponseForRelease(review, release) | ||
|
||
expect(transporterMock.sendMail).not.toBeCalled() | ||
}) | ||
|
||
test('that an email is not sent after a response for a an access request review if disabled in config', async () => { | ||
vi.spyOn(config, 'smtp', 'get').mockReturnValue({ | ||
enabled: false, | ||
connection: { | ||
host: 'localhost', | ||
port: 1025, | ||
secure: false, | ||
auth: { user: '', pass: '' }, | ||
tls: { | ||
rejectUnauthorized: false, | ||
}, | ||
}, | ||
from: '"Bailo 📝" <[email protected]>', | ||
}) | ||
await notifyReviewResponseForAccess(review, access) | ||
|
||
expect(transporterMock.sendMail).not.toBeCalled() | ||
}) | ||
|
||
test('that an email is sent for Release Reviews', async () => { | ||
await requestReviewForRelease('user:user', review, release) | ||
|
||
|
@@ -133,12 +171,24 @@ describe('services > smtp > smtp', () => { | |
expect(transporterMock.sendMail.mock.calls.at(0)).toMatchSnapshot() | ||
}) | ||
|
||
test('that an email is not sent if a response for a release review cannot be found', async () => { | ||
await notifyReviewResponseForRelease(new Review({ role: 'owner', responses: [] }), release) | ||
|
||
expect(transporterMock.sendMail).not.toBeCalled() | ||
}) | ||
|
||
test('that an email is sent after a response for a an access request review', async () => { | ||
await notifyReviewResponseForAccess(review, access) | ||
|
||
expect(transporterMock.sendMail.mock.calls.at(0)).toMatchSnapshot() | ||
}) | ||
|
||
test('that an email is not sent if a response for an access request review cannot be found', async () => { | ||
await notifyReviewResponseForAccess(new Review({ role: 'owner', responses: [] }), access) | ||
|
||
expect(transporterMock.sendMail).not.toBeCalled() | ||
}) | ||
|
||
test('that sendEmail is called for each member of a group entity', async () => { | ||
authenticationMock.getUserInformationList.mockReturnValueOnce([ | ||
Promise.resolve({ email: '[email protected]' }), | ||
|
@@ -152,7 +202,7 @@ describe('services > smtp > smtp', () => { | |
|
||
test('that sendEmail is called a maximum of 20 times', async () => { | ||
const users: Promise<{ email: string }>[] = [] | ||
for (let i = 0; i < 20; i += 1) { | ||
for (let i = 0; i <= 20; i += 1) { | ||
users[i] = Promise.resolve({ email: `member${i}@email.com` }) | ||
} | ||
authenticationMock.getUserInformationList.mockReturnValueOnce(users) | ||
|