mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
fix: noop if no slack flagging url is passed in
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
import { IncomingWebhook } from '@slack/client';
|
import { IncomingWebhook } from '@slack/client';
|
||||||
|
import requireAgain from 'require-again';
|
||||||
import slack from '../../../../../website/server/libs/slack';
|
import slack from '../../../../../website/server/libs/slack';
|
||||||
|
import logger from '../../../../../website/server/libs/logger';
|
||||||
import { TAVERN_ID } from '../../../../../website/server/models/group';
|
import { TAVERN_ID } from '../../../../../website/server/models/group';
|
||||||
|
import nconf from 'nconf';
|
||||||
|
|
||||||
describe('slack', () => {
|
describe('slack', () => {
|
||||||
describe('sendFlagNotification', () => {
|
describe('sendFlagNotification', () => {
|
||||||
@@ -93,5 +96,21 @@ describe('slack', () => {
|
|||||||
})],
|
})],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('noops if no flagging url is provided', () => {
|
||||||
|
sandbox.stub(nconf, 'get').withArgs('SLACK:FLAGGING_URL').returns('');
|
||||||
|
sandbox.stub(logger, 'error');
|
||||||
|
let reRequiredSlack = requireAgain('../../../../../website/server/libs/slack');
|
||||||
|
|
||||||
|
expect(logger.error).to.be.calledOnce;
|
||||||
|
|
||||||
|
reRequiredSlack.sendFlagNotification({
|
||||||
|
flagger,
|
||||||
|
group,
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(IncomingWebhook.prototype.send).to.not.be.called;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
import { IncomingWebhook } from '@slack/client';
|
import { IncomingWebhook } from '@slack/client';
|
||||||
|
import logger from './logger';
|
||||||
import { TAVERN_ID } from '../models/group';
|
import { TAVERN_ID } from '../models/group';
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
|
|
||||||
@@ -7,13 +8,22 @@ const SLACK_FLAGGING_URL = nconf.get('SLACK:FLAGGING_URL');
|
|||||||
const SLACK_FLAGGING_FOOTER_LINK = nconf.get('SLACK:FLAGGING_FOOTER_LINK');
|
const SLACK_FLAGGING_FOOTER_LINK = nconf.get('SLACK:FLAGGING_FOOTER_LINK');
|
||||||
const BASE_URL = nconf.get('BASE_URL');
|
const BASE_URL = nconf.get('BASE_URL');
|
||||||
|
|
||||||
let flagSlack = new IncomingWebhook(SLACK_FLAGGING_URL);
|
let flagSlack;
|
||||||
|
|
||||||
|
try {
|
||||||
|
flagSlack = new IncomingWebhook(SLACK_FLAGGING_URL);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
function sendFlagNotification ({
|
function sendFlagNotification ({
|
||||||
flagger,
|
flagger,
|
||||||
group,
|
group,
|
||||||
message,
|
message,
|
||||||
}) {
|
}) {
|
||||||
|
if (!SLACK_FLAGGING_URL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let titleLink;
|
let titleLink;
|
||||||
let title = `Flag in ${group.name}`;
|
let title = `Flag in ${group.name}`;
|
||||||
let text = `${flagger.profile.name} (${flagger.id}) flagged a message`;
|
let text = `${flagger.profile.name} (${flagger.id}) flagged a message`;
|
||||||
|
|||||||
Reference in New Issue
Block a user