Skip to content

Commit 7736b7d

Browse files
committed
Start the test suite
For starters, let's just verify that the webhook validation manages to dismiss requests that have the wrong method. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 5227939 commit 7736b7d

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

__tests__/index.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const index = require('../GitForWindowsHelper/index')
2+
3+
process.env['GITHUB_WEBHOOK_SECRET'] = 'for-testing'
4+
5+
test('reject requests other than webhook payloads', async () => {
6+
const context = {
7+
log: jest.fn(),
8+
req: {
9+
method: 'GET'
10+
}
11+
}
12+
13+
const expectInvalidWebhook = async (message) => {
14+
context.log.mockClear()
15+
expect(await index(context, context.req)).toBeUndefined()
16+
expect(context.log).toHaveBeenCalledTimes(1)
17+
// context.log was called with an instance of an `Error`
18+
expect(context.log.mock.calls[0][0].message).toEqual(message)
19+
expect(context.res).toEqual({
20+
body: `Go away, you are not a valid GitHub webhook: Error: ${message}`,
21+
headers: undefined,
22+
status: 403
23+
})
24+
}
25+
26+
await expectInvalidWebhook('Unexpected method: GET')
27+
})

0 commit comments

Comments
 (0)