-
Notifications
You must be signed in to change notification settings - Fork 17
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 BC-5736-redis-for-tldraw
- Loading branch information
Showing
6 changed files
with
95 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IMailConfig { | ||
ADDITIONAL_BLACKLISTED_EMAIL_DOMAINS: string[]; | ||
} |
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,7 +1,10 @@ | ||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { createMock } from '@golevelup/ts-jest'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Mail } from './mail.interface'; | ||
import { MailService } from './mail.service'; | ||
import { IMailConfig } from './interfaces/mail-config'; | ||
|
||
describe('MailService', () => { | ||
let module: TestingModule; | ||
|
@@ -19,6 +22,10 @@ describe('MailService', () => { | |
MailService, | ||
{ provide: AmqpConnection, useValue: { publish: () => {} } }, | ||
{ provide: 'MAIL_SERVICE_OPTIONS', useValue: mailServiceOptions }, | ||
{ | ||
provide: ConfigService, | ||
useValue: createMock<ConfigService<IMailConfig, true>>({ get: () => ['schul-cloud.org', 'example.com'] }), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
|
@@ -34,13 +41,43 @@ describe('MailService', () => { | |
expect(service).toBeDefined(); | ||
}); | ||
|
||
it('should send given data to queue', async () => { | ||
const data: Mail = { mail: { plainTextContent: 'content', subject: 'Test' }, recipients: ['[email protected]'] }; | ||
const amqpConnectionSpy = jest.spyOn(amqpConnection, 'publish'); | ||
describe('send', () => { | ||
describe('when recipients array is empty', () => { | ||
it('should not send email', async () => { | ||
const data: Mail = { | ||
mail: { plainTextContent: 'content', subject: 'Test' }, | ||
recipients: ['[email protected]'], | ||
}; | ||
|
||
await service.send(data); | ||
const amqpConnectionSpy = jest.spyOn(amqpConnection, 'publish'); | ||
|
||
const expectedParams = [mailServiceOptions.exchange, mailServiceOptions.routingKey, data, { persistent: true }]; | ||
expect(amqpConnectionSpy).toHaveBeenCalledWith(...expectedParams); | ||
await service.send(data); | ||
|
||
expect(amqpConnectionSpy).toHaveBeenCalledTimes(0); | ||
}); | ||
}); | ||
describe('when sending email', () => { | ||
it('should remove email address that have blacklisted domain and send given data to queue', async () => { | ||
const data: Mail = { | ||
mail: { plainTextContent: 'content', subject: 'Test' }, | ||
recipients: ['[email protected]', '[email protected]', '[email protected]', '[email protected]'], | ||
cc: ['[email protected]', '[email protected]', '[email protected]'], | ||
bcc: ['[email protected]', '[email protected]', '[email protected]'], | ||
replyTo: ['[email protected]', '[email protected]', '[email protected]'], | ||
}; | ||
|
||
const amqpConnectionSpy = jest.spyOn(amqpConnection, 'publish'); | ||
|
||
await service.send(data); | ||
|
||
expect(data.recipients).toEqual(['[email protected]']); | ||
expect(data.cc).toEqual([]); | ||
expect(data.bcc).toEqual(['[email protected]']); | ||
expect(data.replyTo).toEqual(['[email protected]']); | ||
|
||
const expectedParams = [mailServiceOptions.exchange, mailServiceOptions.routingKey, data, { persistent: true }]; | ||
expect(amqpConnectionSpy).toHaveBeenCalledWith(...expectedParams); | ||
}); | ||
}); | ||
}); | ||
}); |
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