Skip to content

Commit 3beb8d6

Browse files
committed
add test for handler
1 parent 8504d4f commit 3beb8d6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/index.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { serverless } = require('../')
2+
3+
describe('serverless-lambda', () => {
4+
let spy, handler, context
5+
6+
beforeEach(() => {
7+
context = { done: jest.fn() }
8+
spy = jest.fn()
9+
handler = serverless(async app => {
10+
app.auth = () => Promise.resolve({})
11+
app.on('issues', spy)
12+
})
13+
})
14+
15+
it('responds with the homepage', async () => {
16+
const event = { httpMethod: 'GET', path: '/probot' }
17+
await handler(event, context)
18+
expect(context.done).toHaveBeenCalled()
19+
expect(context.done.mock.calls[0][0]).toMatchSnapshot()
20+
})
21+
22+
it('calls the event handler', async () => {
23+
const event = {
24+
body: {
25+
installation: { id: 1 }
26+
},
27+
headers: {
28+
'x-github-event': 'issues',
29+
'x-github-delivery': 123
30+
}
31+
}
32+
33+
await handler(event, context)
34+
expect(context.done).toHaveBeenCalled()
35+
expect(spy).toHaveBeenCalled()
36+
})
37+
})

0 commit comments

Comments
 (0)