diff --git a/test/api/v3/unit/libs/slack.js b/test/api/v3/unit/libs/slack.js index 3e48ade892..befd41a706 100644 --- a/test/api/v3/unit/libs/slack.js +++ b/test/api/v3/unit/libs/slack.js @@ -8,27 +8,30 @@ import nconf from 'nconf'; describe('slack', () => { describe('sendFlagNotification', () => { - let flagger, group, message; + let data; beforeEach(() => { sandbox.stub(IncomingWebhook.prototype, 'send'); - flagger = { - id: 'flagger-id', - profile: { - name: 'flagger', + data = { + authorEmail: 'author@example.com', + flagger: { + id: 'flagger-id', + profile: { + name: 'flagger', + }, + }, + group: { + id: 'group-id', + privacy: 'private', + name: 'Some group', + type: 'guild', + }, + message: { + id: 'chat-id', + user: 'Author', + uuid: 'author-id', + text: 'some text', }, - }; - group = { - id: 'group-id', - privacy: 'private', - name: 'Some group', - type: 'guild', - }; - message = { - id: 'chat-id', - user: 'Author', - uuid: 'author-id', - text: 'some text', }; }); @@ -37,11 +40,7 @@ describe('slack', () => { }); it('sends a slack webhook', () => { - slack.sendFlagNotification({ - flagger, - group, - message, - }); + slack.sendFlagNotification(data); expect(IncomingWebhook.prototype.send).to.be.calledOnce; expect(IncomingWebhook.prototype.send).to.be.calledWith({ @@ -49,7 +48,7 @@ describe('slack', () => { attachments: [{ fallback: 'Flag Message', color: 'danger', - author_name: 'Author - author-id', + author_name: 'Author - author@example.com - author-id', title: 'Flag in Some group - (private guild)', title_link: undefined, text: 'some text', @@ -62,13 +61,9 @@ describe('slack', () => { }); it('includes a title link if guild is public', () => { - group.privacy = 'public'; + data.group.privacy = 'public'; - slack.sendFlagNotification({ - flagger, - group, - message, - }); + slack.sendFlagNotification(data); expect(IncomingWebhook.prototype.send).to.be.calledWithMatch({ attachments: [sandbox.match({ @@ -79,15 +74,11 @@ describe('slack', () => { }); it('links to tavern', () => { - group.privacy = 'public'; - group.name = 'Tavern'; - group.id = TAVERN_ID; + data.group.privacy = 'public'; + data.group.name = 'Tavern'; + data.group.id = TAVERN_ID; - slack.sendFlagNotification({ - flagger, - group, - message, - }); + slack.sendFlagNotification(data); expect(IncomingWebhook.prototype.send).to.be.calledWithMatch({ attachments: [sandbox.match({ @@ -98,14 +89,10 @@ describe('slack', () => { }); it('provides name for system message', () => { - message.uuid = 'system'; - delete message.user; + data.message.uuid = 'system'; + delete data.message.user; - slack.sendFlagNotification({ - flagger, - group, - message, - }); + slack.sendFlagNotification(data); expect(IncomingWebhook.prototype.send).to.be.calledWithMatch({ attachments: [sandbox.match({ @@ -121,11 +108,7 @@ describe('slack', () => { expect(logger.error).to.be.calledOnce; - reRequiredSlack.sendFlagNotification({ - flagger, - group, - message, - }); + reRequiredSlack.sendFlagNotification(data); expect(IncomingWebhook.prototype.send).to.not.be.called; }); diff --git a/website/server/controllers/api-v3/chat.js b/website/server/controllers/api-v3/chat.js index 988b3a893a..89c6aafa6c 100644 --- a/website/server/controllers/api-v3/chat.js +++ b/website/server/controllers/api-v3/chat.js @@ -270,6 +270,7 @@ api.flagChat = { ]); slack.sendFlagNotification({ + authorEmail, flagger: user, group, message, diff --git a/website/server/libs/slack.js b/website/server/libs/slack.js index 14350d8a8b..af507c1d87 100644 --- a/website/server/libs/slack.js +++ b/website/server/libs/slack.js @@ -17,6 +17,7 @@ try { } function sendFlagNotification ({ + authorEmail, flagger, group, message, @@ -40,7 +41,7 @@ function sendFlagNotification ({ if (!message.user && message.uuid === 'system') { authorName = 'System Message'; } else { - authorName = `${message.user} - ${message.uuid}`; + authorName = `${message.user} - ${authorEmail} - ${message.uuid}`; } flagSlack.send({