This commit is contained in:
parent
31cf5149be
commit
5abc95af51
|
@ -0,0 +1,36 @@
|
|||
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() => {
|
||||
const hasAdministrativeAcls = await hasAcl('administrative', id.administrative);
|
||||
const hasProductionBossAcls = await hasAcl('productionBoss', id.productionBoss);
|
||||
|
||||
expect(hasAdministrativeAcls).toBeTruthy();
|
||||
expect(hasProductionBossAcls).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not get administrative acls', async() => {
|
||||
const hasAdministrativeAcls = await hasAcl('administrative', id.employee);
|
||||
|
||||
expect(hasAdministrativeAcls).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should get the $authenticated acls', async() => {
|
||||
const hasAuthAcls = await hasAcl('$authenticated', id.employee);
|
||||
|
||||
expect(hasAuthAcls).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should get the $everyone acls', async() => {
|
||||
const hasEveryoneAcls = await hasAcl('$everyone', id.employee);
|
||||
|
||||
expect(hasEveryoneAcls).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);
|
||||
};
|
|
@ -17,6 +17,7 @@ async function init() {
|
|||
err => err ? reject(err) : resolve());
|
||||
});
|
||||
// FIXME: Workaround to wait for loopback to be ready
|
||||
app.emit('started');
|
||||
await app.models.Application.status();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue