@ -71,13 +71,14 @@ router.post('hooks.slack', async ctx => {
|
||||
color: document.collection.color,
|
||||
title: document.title,
|
||||
title_link: `${process.env.URL}${document.getUrl()}`,
|
||||
footer: document.collection.name,
|
||||
text: document.getSummary(),
|
||||
ts: new Date(document.updatedAt).getTime(),
|
||||
ts: document.getTimestamp(),
|
||||
});
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
text: `This is what we found…`,
|
||||
text: `This is what we found for "${text}"…`,
|
||||
attachments,
|
||||
};
|
||||
} else {
|
||||
|
@ -65,18 +65,20 @@ describe('#hooks.slack', async () => {
|
||||
});
|
||||
|
||||
it('should return search results', async () => {
|
||||
const { user } = await seed();
|
||||
const { user, document, collection } = await seed();
|
||||
|
||||
const res = await server.post('/api/hooks.slack', {
|
||||
body: {
|
||||
token: process.env.SLACK_VERIFICATION_TOKEN,
|
||||
user_id: user.slackId,
|
||||
text: 'Welcome',
|
||||
text: document.title,
|
||||
},
|
||||
});
|
||||
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].footer).toEqual(collection.name);
|
||||
});
|
||||
|
||||
it('should error if unknown user', async () => {
|
||||
|
@ -221,6 +221,10 @@ Document.addHook('afterUpdate', model =>
|
||||
|
||||
// Instance methods
|
||||
|
||||
Document.prototype.getTimestamp = function() {
|
||||
return Math.round(new Date(this.updatedAt).getTime() / 1000);
|
||||
};
|
||||
|
||||
Document.prototype.getSummary = function() {
|
||||
const value = Markdown.deserialize(this.text);
|
||||
const plain = Plain.serialize(value);
|
||||
|
Reference in New Issue
Block a user