Skip to content

Commit

Permalink
SLSCMN-8 email service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Dec 18, 2023
1 parent 830d5da commit 7d1a6d6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/__fixtures__/email-service.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Email } from '../services';

export const emailFixture: Email = {
destinations: [{ to: ['[email protected]'] }],
templateName: 'template-name',
templateData: { foo: 'bar' },
};
32 changes: 32 additions & 0 deletions src/services/__tests__/email-service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import EmailService from '../email-service';

import SQSService from '../sqs-service';
import { emailFixture } from '../../__fixtures__/email-service.fixture';

describe('EmailService', () => {
const QUEUE_URL = 'queue-url';
const sendSpy = jest.spyOn(SQSService, 'sendMessage');

beforeEach(() => {
sendSpy.mockResolvedValue({ $metadata: {} });
});

it('should be defined', () => {
expect(EmailService).toBeDefined();
expect(EmailService.send).toBeDefined();
});

it('should send email', async () => {
await EmailService.send(emailFixture, QUEUE_URL);

expect(sendSpy).toHaveBeenCalledTimes(1);
expect(sendSpy).toHaveBeenCalledWith({
QueueUrl: QUEUE_URL,
MessageBody: JSON.stringify({
data: emailFixture.templateData,
destinations: emailFixture.destinations,
template: emailFixture.templateName,
}),
});
});
});

0 comments on commit 7d1a6d6

Please sign in to comment.