diff --git a/src/routers/permission.js b/src/routers/permission.js index e0538e8..de41e3b 100644 --- a/src/routers/permission.js +++ b/src/routers/permission.js @@ -80,11 +80,16 @@ router.get('/permission/:id', auth, [ } }); -router.patch('/permission/:id', auth, verifyInputUpdateParameters([ - 'action', 'active', 'router', 'identifiedBy' -]), [ - check('id').isMongoId() -], validate, async (req, res) => { +router.patch('/permission/:id', auth, [ + check('id').isMongoId(), + body('action').isString().optional(), + body('active').isBoolean().optional(), + body('router').isString().optional(), + body('identifiedBy').isString().optional(), + body('environments').isArray().optional() +], validate, verifyInputUpdateParameters([ + 'action', 'active', 'router', 'identifiedBy', 'environments' +]), async (req, res) => { await updatePermission(req, res); }); diff --git a/tests/permission.test.js b/tests/permission.test.js index b92a9b7..ba56cd0 100644 --- a/tests/permission.test.js +++ b/tests/permission.test.js @@ -453,4 +453,30 @@ describe('Updating permission values tests', () => { const permission = await Permission.findById(permission1Id).lean().exec(); expect(permission.values.length).toBe(0); }); +}); + +describe('Updating environments tests', () => { + beforeAll(setupDatabase); + + test('PERMISSION_SUITE - Should set an environment to the permission', async () => { + await request(app) + .patch('/permission/' + permission1Id) + .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .send({ + environments: ['development'] + }).expect(200); + + // DB validation + const permission = await Permission.findById(permission1Id).lean().exec(); + expect(permission.environments.includes('development')).toEqual(true); + }); + + test('PERMISSION_SUITE - Should NOT set an environment to the permission - Invalid value (not an array)', async () => { + await request(app) + .patch('/permission/' + permission1Id) + .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .send({ + environments: 'development' + }).expect(422); + }); }); \ No newline at end of file