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
11 changes: 9 additions & 2 deletions src/services/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { NotFoundError } from '../exceptions/index.js';

export function response(element, onErrorMessage) {
if (!element) throw new NotFoundError(onErrorMessage);
if (!element) {
throw new NotFoundError(onErrorMessage);
}

return element;
}
}

export function isQueryValid(where) {
return Object.values(where).some(value => value != null);
}
5 changes: 5 additions & 0 deletions src/services/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getDomainById, updateDomainVersion } from './domain.js';
import { getEnvironment } from './environment.js';
import { getGroupConfig } from './group-config.js';
import { containsValue } from '../helpers/index.js';
import { isQueryValid } from './common.js';

/**
* Validates if ticket already exists, if so, return it.
Expand Down Expand Up @@ -63,6 +64,10 @@ export async function getSlackOrError(where) {
}

export async function getSlack(where) {
if (!isQueryValid(where)) {
throw new NotFoundError('Slack installation not found - no valid query provided');
}

const query = Slack.findOne();

if (where.id) query.where('_id', where.id);
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/db_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const slack = {
incoming_webhook_channel_id : 'CHANNEL_ID'
},
};
domainDocument.integrations = { slack: slack._id };

export const setupDatabase = async () => {
await ConfigStrategy.deleteMany().exec();
Expand Down
20 changes: 20 additions & 0 deletions tests/slack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ describe('Slack Installation', () => {
mock1_slack_installation.installation_payload.incoming_webhook_channel);
});

test('SLACK_SUITE - Should NOT query installation by Domain - Domain has no Slack integration', async () => {
//given
const domain = await getDomainById(domainId);
const slackId = domain.integrations.slack;
domain.integrations.slack = null;
await domain.save();

//test
const response = await request(app)
.get(`/slack/v1/installation/${String(domainId)}`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(404);

expect(response.body.error).toBe('Slack installation not found - no valid query provided');

//teardown
domain.integrations.slack = slackId;
await domain.save();
});

test('SLACK_SUITE - Should NOT query installation by Domain - Domain not found', async () => {
await request(app)
.get(`/slack/v1/installation/${new mongoose.Types.ObjectId()}`)
Expand Down