/
app.test.ts
51 lines (43 loc) · 1.42 KB
/
app.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { SQSEvent } from 'aws-lambda';
import { lambdaHandler, TEmailSendData } from './app';
import { SESClient } from '@aws-sdk/client-ses';
describe('Unit test for app handler', function () {
const sesClientSendMock = jest.spyOn(SESClient.prototype, 'send').mockImplementation(() => ({}));
beforeEach(() => {
sesClientSendMock.mockClear();
});
it('runs at least 1 second', async () => {
const start = Date.now();
await lambdaHandler(testEvent);
const end = Date.now();
expect(end - start).toBeGreaterThanOrEqual(1000);
});
it('should call send function', async () => {
await lambdaHandler(testEvent);
expect(sesClientSendMock).toHaveBeenCalledTimes(1);
});
});
const testEvent: SQSEvent = {
Records: [
{
messageId: '19dd0b57-b21e-4ac1-a2ac-11b019e8e7b3',
receiptHandle: 'MessageReceiptHandle',
body: JSON.stringify({
to: 'testy.mctestison@gmail.com',
subject: 'Favorite Fruit',
html: '<p>Banana</p>',
} as TEmailSendData),
attributes: {
ApproximateReceiveCount: '1',
SentTimestamp: '1523232000000',
SenderId: '123456789012',
ApproximateFirstReceiveTimestamp: '1523232000001',
},
messageAttributes: {},
md5OfBody: '7b270e59b47ff90a553787216d55d91d',
eventSource: 'aws:sqs',
eventSourceARN: 'arn:aws:sqs:us-east-2:123456789012:MyQueue',
awsRegion: 'eu-central-1',
},
],
};