Fixes 400 error response from slack hook
Split results into individual attachments
This commit is contained in:
@ -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);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user