Fixes 400 error response from slack hook

Split results into individual attachments
This commit is contained in:
Tom Moor
2018-01-28 17:00:20 -08:00
parent d65f7577d4
commit 66fa88fcab
3 changed files with 72 additions and 18 deletions

View File

@ -47,3 +47,59 @@ describe('#hooks.unfurl', async () => {
expect(Slack.post).toHaveBeenCalled();
});
});
describe('#hooks.slack', async () => {
it('should return no matches', async () => {
const { user } = await seed();
const res = await server.post('/api/hooks.slack', {
body: {
token: process.env.SLACK_VERIFICATION_TOKEN,
user_id: user.slackId,
text: 'dsfkndfskndsfkn',
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.attachments).toEqual(undefined);
});
it('should return search results', async () => {
const { user } = await seed();
const res = await server.post('/api/hooks.slack', {
body: {
token: process.env.SLACK_VERIFICATION_TOKEN,
user_id: user.slackId,
text: 'Welcome',
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.attachments.length).toEqual(1);
});
it('should error if unknown user', async () => {
const res = await server.post('/api/hooks.slack', {
body: {
token: process.env.SLACK_VERIFICATION_TOKEN,
user_id: 'not-a-user-id',
text: 'Welcome',
},
});
expect(res.status).toEqual(400);
});
it('should error if incorrect verification token', async () => {
const { user } = await seed();
const res = await server.post('/api/hooks.slack', {
body: {
token: 'wrong-verification-token',
user_id: user.slackId,
text: 'Welcome',
},
});
expect(res.status).toEqual(401);
});
});