-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.test.js
62 lines (57 loc) · 1.82 KB
/
message.test.js
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
52
53
54
55
56
57
58
59
60
61
62
import { verifyRequest } from './libs/slack';
import eventHandler from './events';
import { main } from './message';
jest.mock('./libs/slack');
jest.mock('./events');
describe('message handler', () => {
it('verifies requests', async () => {
const event = { body: null };
const context = { context: true };
verifyRequest.mockReturnValue(false);
try {
await main(event, context);
expect(false).toBeTruthy();
} catch (err) {
expect(true).toBeTruthy();
}
expect(verifyRequest).toBeCalledWith(event);
});
it('reflects challenge for url_verification', async () => {
const event = {
body: JSON.stringify({
type: 'url_verification',
challenge: 'testChallenge',
}),
};
const context = { context: true };
verifyRequest.mockReturnValue(true);
const response = await main(event, context);
expect(response.statusCode).toEqual(200);
expect(JSON.parse(response.body)).toEqual({ challenge: 'testChallenge' });
});
it('hands off to event handler for event_callback', async () => {
const event = {
body: JSON.stringify({
type: 'event_callback',
}),
};
const context = { context: true };
verifyRequest.mockReturnValue(true);
eventHandler.mockResolvedValue({ event: true });
const response = await main(event, context);
expect(response.statusCode).toEqual(200);
expect(JSON.parse(response.body)).toEqual({ event: true });
});
it('other events just return true', async () => {
const event = {
body: JSON.stringify({
type: 'gibberish',
}),
};
const context = { context: true };
verifyRequest.mockReturnValue(true);
const response = await main(event, context);
expect(response.statusCode).toEqual(200);
expect(JSON.parse(response.body)).toEqual(true);
});
});