All checks were successful
farmcontrol/farmcontrol-api/pipeline/head This commit looks good
This commit introduces a new feature for managing user groups within the application, including the creation of a `usergroup.schema.js` file for the Mongoose schema and corresponding route handlers for CRUD operations. Additionally, the permission settings functionality has been refactored to use a singular `permissionSetting` model instead of the previous plural form. Tests have been added to ensure the functionality of both user groups and permission settings services, enhancing the application's capability to manage user roles and permissions effectively.
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
import { applyPermissionSettingsList } from '../permissions.js';
|
|
|
|
describe('applyPermissionSettingsList', () => {
|
|
it('applies permission settings in order and inherits intermediate values', () => {
|
|
const result = applyPermissionSettingsList([
|
|
{
|
|
permissions: {
|
|
user: { info: true, edit: false, delete: true },
|
|
printer: { info: true },
|
|
},
|
|
},
|
|
{
|
|
permissions: {
|
|
user: { edit: true, delete: null },
|
|
printer: { info: null, delete: false },
|
|
},
|
|
},
|
|
]);
|
|
|
|
expect(result).toEqual({
|
|
user: { info: true, edit: true, delete: true },
|
|
printer: { info: true, delete: false },
|
|
});
|
|
});
|
|
|
|
it('returns an empty object when nothing is explicitly set', () => {
|
|
expect(applyPermissionSettingsList([{ permissions: { user: { info: null } } }])).toEqual({});
|
|
});
|
|
|
|
it('applies group permissions first, then user permission settings', () => {
|
|
const result = applyPermissionSettingsList([
|
|
{
|
|
permissions: {
|
|
user: { info: true, edit: false },
|
|
printer: { info: true },
|
|
},
|
|
},
|
|
{
|
|
permissions: {
|
|
user: { delete: true },
|
|
},
|
|
},
|
|
{
|
|
permissions: {
|
|
user: { edit: true },
|
|
printer: { info: false },
|
|
},
|
|
},
|
|
]);
|
|
|
|
expect(result).toEqual({
|
|
user: { info: true, edit: true, delete: true },
|
|
printer: { info: false },
|
|
});
|
|
});
|
|
});
|