salix/back/methods/vn-user/specs/acls.spec.js

28 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2024-05-17 09:29:16 +00:00
const {models} = require('vn-loopback/server/server');
const id = {administrative: 5, employee: 1, productionBoss: 50};
describe('VnUser acls()', () => {
it('should get its owns acls', async() => {
2024-05-17 09:35:29 +00:00
expect(await hasAcl('administrative', id.administrative)).toBeTruthy();
expect(await hasAcl('productionBoss', id.productionBoss)).toBeTruthy();
2024-05-17 09:29:16 +00:00
});
it('should not get administrative acls', async() => {
2024-05-17 09:35:29 +00:00
expect(await hasAcl('administrative', id.employee)).toBeFalsy();
2024-05-17 09:29:16 +00:00
});
it('should get the $authenticated acls', async() => {
2024-05-17 09:35:29 +00:00
expect(await hasAcl('$authenticated', id.employee)).toBeTruthy();
2024-05-17 09:29:16 +00:00
});
it('should get the $everyone acls', async() => {
2024-05-17 09:35:29 +00:00
expect(await hasAcl('$everyone', id.employee)).toBeTruthy();
2024-05-17 09:29:16 +00:00
});
});
const hasAcl = async(role, userId) => {
const ctx = {req: {accessToken: {userId}, headers: {origin: 'http://localhost'}}};
const acls = await models.VnUser.acls(ctx);
return Object.values(acls).some(acl => acl.principalId === role);
};