Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/external/switcher-api-facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ export async function checkSlackIntegration(value) {
]), 'Slack Integration is not available.');
}

export async function checkSlackAvailability(admin, feature) {
if (process.env.SWITCHER_API_ENABLE != 'true')
return true;

if (!process.env.SWITCHER_SLACK_JWT_SECRET)
return false;

const result = await checkFeature(feature, [checkValue(admin._id)], [
SwitcherKeys.SLACK_INTEGRATION,
SwitcherKeys.SLACK_UPDATE
]);

return result;
}

export function notifyAcCreation(adminid) {
if (process.env.SWITCHER_API_ENABLE != 'true')
return;
Expand Down
15 changes: 2 additions & 13 deletions src/services/slack.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Slack from '../models/slack';
import { checkValue, Switcher } from 'switcher-client';
import { TicketStatusType, SLACK_SUB, TicketValidationType } from '../models/slack_ticket';
import { BadRequestError, NotFoundError, PermissionError } from '../exceptions';
import { checkSlackIntegration, checkFeature, SwitcherKeys } from '../external/switcher-api-facade';
import { checkSlackIntegration, checkSlackAvailability } from '../external/switcher-api-facade';
import { getConfig } from './config';
import { getDomainById } from './domain';
import { getEnvironment } from './environment';
import { getGroupConfig } from './group-config';
import { containsValue } from '../helpers';
import Logger from '../helpers/logger';

/**
* Validates if ticket already exists, if so, return it.
Expand Down Expand Up @@ -71,16 +69,7 @@ export async function getSlack(where) {
}

export async function checkAvailability(admin, feature) {
if (!process.env.SWITCHER_SLACK_JWT_SECRET)
return false;

const result = await checkFeature(feature, [checkValue(admin._id)], [
SwitcherKeys.SLACK_INTEGRATION,
SwitcherKeys.SLACK_UPDATE
]);

Logger.info(`checkAvailability [${feature}]`, { log: Switcher.getLogger(feature) });
return result;
return checkSlackAvailability(admin, feature);
}

export async function createSlackInstallation(args) {
Expand Down
15 changes: 14 additions & 1 deletion tests/slack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Slack Feature Availability', () => {
process.env.SWITCHER_SLACK_JWT_SECRET = 'SLACK_APP_SECRET';
});

test('SLACK_SUITE - Should check feature - Available', async () => {
test('SLACK_SUITE - Should check feature - Available (API enabled)', async () => {
Switcher.assume('SLACK_INTEGRATION').true();
const response = await request(app)
.post('/slack/v1/availability')
Expand All @@ -72,6 +72,19 @@ describe('Slack Feature Availability', () => {
expect(response.body.result).toBe(true);
});

test('SLACK_SUITE - Should check feature - Available (API disabled)', async () => {
process.env.SWITCHER_API_ENABLE = false;
const response = await request(app)
.post('/slack/v1/availability')
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
feature: 'SLACK_INTEGRATION'
}).expect(200);

expect(response.body.result).toBe(true);
process.env.SWITCHER_API_ENABLE = true;
});

test('SLACK_SUITE - Should check feature - Not Available', async () => {
Switcher.assume('SLACK_INTEGRATION').false();
const response = await request(app)
Expand Down