From 827d1bc0a2330f1df634189aadc2637f179c56a7 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Mon, 8 May 2023 22:44:25 -0700 Subject: [PATCH] Fixes #407 - resolveComponent from Config route --- src/app.js | 2 +- src/routers/config.js | 2 +- tests/config.test.js | 31 ++++++++++++++----------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/app.js b/src/app.js index fe8a348..4fd3aa7 100644 --- a/src/app.js +++ b/src/app.js @@ -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); diff --git a/src/routers/config.js b/src/routers/config.js index c8704b8..eed69e4 100644 --- a/src/routers/config.js +++ b/src/routers/config.js @@ -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' }); } diff --git a/tests/config.test.js b/tests/config.test.js index 6a188a5..bc131b8 100644 --- a/tests/config.test.js +++ b/tests/config.test.js @@ -17,7 +17,8 @@ import { configId1, config1Document, configId2, - configStrategyId + configStrategyId, + component1 } from './fixtures/db_api'; afterAll(async () => { @@ -138,9 +139,9 @@ 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); @@ -148,24 +149,20 @@ describe('Testing fetch configuration info', () => { 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}`)