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: 10 additions & 5 deletions src/routers/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
26 changes: 26 additions & 0 deletions tests/permission.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});