Return relevant context in search results returned to slack slash command

This commit is contained in:
Tom Moor
2018-08-05 00:34:08 -07:00
parent 71830d7c77
commit fc7373a6f5
4 changed files with 19 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import TestServer from 'fetch-test-server';
import app from '..';
import { Authentication } from '../models';
import { flushdb, seed } from '../test/support';
import { buildDocument } from '../test/factories';
import * as Slack from '../slack';
const server = new TestServer(app.callback());
@ -65,19 +66,26 @@ describe('#hooks.slack', async () => {
});
it('should return search results', async () => {
const { user, document, collection } = await seed();
const { user, collection } = await seed();
const document = await buildDocument({
title: 'This title contains a search term',
userId: user.id,
teamId: user.teamId,
});
const res = await server.post('/api/hooks.slack', {
body: {
token: process.env.SLACK_VERIFICATION_TOKEN,
user_id: user.serviceId,
text: document.title,
text: 'contains',
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.attachments.length).toEqual(1);
expect(body.attachments[0].title).toEqual(document.title);
expect(body.attachments[0].text).toEqual(
'This title *contains* a search term'
);
expect(body.attachments[0].footer).toEqual(collection.name);
});