From 97a069642d79320f08bad2bc49b2b1f6a87c5be1 Mon Sep 17 00:00:00 2001 From: Isabelle Lavandero <30595954+thefifthisa@users.noreply.github.com> Date: Fri, 15 Jun 2018 17:01:10 +0800 Subject: [PATCH] Add timestamp to moderator Slack messages (fixes #10441) (#10443) * add timestamp to moderator Slack messages * fix test errors * import moment, condense formatting * add timestamp to author_name variable * update test to include timestamp, fix footer matching * change ISODate to Date * update test to include timestamp --- test/api/v3/unit/libs/slack.js | 9 +++++++-- website/server/libs/slack.js | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/test/api/v3/unit/libs/slack.js b/test/api/v3/unit/libs/slack.js index e660a340d2..9a6d183d33 100644 --- a/test/api/v3/unit/libs/slack.js +++ b/test/api/v3/unit/libs/slack.js @@ -5,6 +5,7 @@ import slack from '../../../../../website/server/libs/slack'; import logger from '../../../../../website/server/libs/logger'; import { TAVERN_ID } from '../../../../../website/server/models/group'; import nconf from 'nconf'; +import moment from 'moment'; describe('slack', () => { describe('sendFlagNotification', () => { @@ -45,13 +46,15 @@ describe('slack', () => { it('sends a slack webhook', () => { slack.sendFlagNotification(data); + const timestamp = `${moment(data.message.timestamp).utc().format('YYYY-MM-DD HH:mm')} UTC`; + expect(IncomingWebhook.prototype.send).to.be.calledOnce; expect(IncomingWebhook.prototype.send).to.be.calledWith({ text: 'flagger (flagger-id; language: flagger-lang) flagged a message', attachments: [{ fallback: 'Flag Message', color: 'danger', - author_name: 'Author - author@example.com - author-id', + author_name: `Author - author@example.com - author-id\n${timestamp}`, title: 'Flag in Some group - (private guild)', title_link: undefined, text: 'some text', @@ -97,9 +100,11 @@ describe('slack', () => { slack.sendFlagNotification(data); + const timestamp = `${moment(data.message.timestamp).utc().format('YYYY-MM-DD HH:mm')} UTC`; + expect(IncomingWebhook.prototype.send).to.be.calledWithMatch({ attachments: [sandbox.match({ - author_name: 'System Message', + author_name: `System Message\n${timestamp}`, })], }); }); diff --git a/website/server/libs/slack.js b/website/server/libs/slack.js index 44dbd9e95b..0ff3eae014 100644 --- a/website/server/libs/slack.js +++ b/website/server/libs/slack.js @@ -3,6 +3,7 @@ import { IncomingWebhook } from '@slack/client'; import logger from './logger'; import { TAVERN_ID } from '../models/group'; import nconf from 'nconf'; +import moment from 'moment'; const SLACK_FLAGGING_URL = nconf.get('SLACK:FLAGGING_URL'); const SLACK_FLAGGING_FOOTER_LINK = nconf.get('SLACK:FLAGGING_FOOTER_LINK'); @@ -52,12 +53,14 @@ function sendFlagNotification ({ authorName = `${message.user} - ${authorEmail} - ${message.uuid}`; } + const timestamp = `${moment(message.timestamp).utc().format('YYYY-MM-DD HH:mm')} UTC`; + flagSlack.send({ text, attachments: [{ fallback: 'Flag Message', color: 'danger', - author_name: authorName, + author_name: `${authorName}\n${timestamp}`, title, title_link: titleLink, text: message.text,