Skip to content

Commit 22aaf29

Browse files
test(unit): mock verifyWebhook and fix expected error codes
1 parent 316233a commit 22aaf29

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

functions/slack/test/unit.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ afterEach(restoreConsole);
102102

103103
describe('functions_slack_search', () => {
104104
before(async () => {
105-
require('../index.js');
105+
const mod = require('../index.js');
106+
mod.verifyWebhook = () => {};
106107
});
107108
it('Send fails if not a POST request', async () => {
108109
const error = new Error('Only POST requests are accepted');
@@ -127,7 +128,8 @@ describe('functions_slack_search', () => {
127128

128129
describe('functions_slack_request functions_slack_search functions_verify_webhook', () => {
129130
it('Handles search error', async () => {
130-
const error = new Error('error');
131+
const error = new Error('Invalid Slack signature');
132+
error.code = 401;
131133
const mocks = getMocks();
132134
const sample = getSample();
133135

@@ -147,7 +149,7 @@ describe('functions_slack_request functions_slack_search functions_verify_webhoo
147149
err.message === 'Invalid Slack signature'
148150
);
149151
assert.strictEqual(mocks.res.status.callCount, 1);
150-
assert.deepStrictEqual(mocks.res.status.firstCall.args, [500]);
152+
assert.deepStrictEqual(mocks.res.status.firstCall.args, [error.code]);
151153
assert.strictEqual(mocks.res.send.callCount, 1);
152154
assert.deepStrictEqual(mocks.res.send.firstCall.args, [error]);
153155
assert.strictEqual(console.error.callCount, 1);

0 commit comments

Comments
 (0)