Skip to content

Commit

Permalink
Fixes #407 - resolveComponent from Config route (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
petruki authored May 9, 2023
1 parent 08d5d95 commit 512bfee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ app.use(slackRouter);
*/

const handler = (req, res, next) =>
createHandler({ schema, context: req})(req, res, next);
createHandler({ schema, context: req })(req, res, next);

// Component: Client API
app.use('/graphql', appAuth, handler);
Expand Down
2 changes: 1 addition & 1 deletion src/routers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ router.get('/config/:id', auth, [
let config = await Services.getConfigById(req.params.id);
config = await verifyOwnership(req.admin, config, config.domain, ActionTypes.READ, RouterTypes.CONFIG, true);

if (req.query.resolveComponents) {
if (req.query.resolveComponents === 'true') {
await config.populate({ path: 'component_list' });
}

Expand Down
31 changes: 14 additions & 17 deletions tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
configId1,
config1Document,
configId2,
configStrategyId
configStrategyId,
component1
} from './fixtures/db_api';

afterAll(async () => {
Expand Down Expand Up @@ -138,34 +139,30 @@ describe('Testing fetch configuration info', () => {
.send().expect(422);
});

test('CONFIG_SUITE - Should get Config information by Id', async () => {
let response = await request(app)
.get('/config/' + configId1 + '?resolveComponents=true')
test('CONFIG_SUITE - Should get Config information by Id - resolveComponents as true', async () => {
const response = await request(app)
.get(`/config/${configId1}?resolveComponents=true`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(200);

expect(String(response.body._id)).toEqual(String(config1Document._id));
expect(response.body.key).toEqual(config1Document.key);
expect(String(response.body.group)).toEqual(String(config1Document.group));
expect(response.body.activated[EnvType.DEFAULT]).toEqual(config1Document.activated.get(EnvType.DEFAULT));
expect(response.body.components[0].name).toEqual(component1.name);
});

// Adding new Config
response = await request(app)
.post('/config/create')
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send({
key: 'NEW_CONFIG456',
description: 'Description of my new Config',
group: groupConfigId
}).expect(201);

await request(app)
.get('/config/' + response.body._id)
test('CONFIG_SUITE - Should get Config information by Id - resolveComponents as false', async () => {
const response = await request(app)
.get(`/config/${configId1}?resolveComponents=false`)
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
.send().expect(200);

expect(String(response.body._id)).toEqual(String(config1Document._id));
expect(response.body.components[0].name).toEqual(undefined);
});

test('CONFIG_SUITE - Should not found Config information by Id', async () => {
test('CONFIG_SUITE - Should not find Config information by Id', async () => {
await request(app)
.get('/config/' + 'NOTEXIST')
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
Expand Down

0 comments on commit 512bfee

Please sign in to comment.