28 lines
1.0 KiB
JavaScript
28 lines
1.0 KiB
JavaScript
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() => {
|
|
expect(await hasAcl('administrative', id.administrative)).toBeTruthy();
|
|
expect(await hasAcl('productionBoss', id.productionBoss)).toBeTruthy();
|
|
});
|
|
|
|
it('should not get administrative acls', async() => {
|
|
expect(await hasAcl('administrative', id.employee)).toBeFalsy();
|
|
});
|
|
|
|
it('should get the $authenticated acls', async() => {
|
|
expect(await hasAcl('$authenticated', id.employee)).toBeTruthy();
|
|
});
|
|
|
|
it('should get the $everyone acls', async() => {
|
|
expect(await hasAcl('$everyone', id.employee)).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
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);
|
|
};
|