salix/front/core/lib/specs/acl-service.spec.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-01-04 06:56:26 +00:00
describe('Service acl', () => {
let aclService;
beforeEach(ngModule('vnCore'));
2018-01-04 06:56:26 +00:00
beforeEach(inject((_aclService_, $httpBackend) => {
$httpBackend.when('GET', `VnUsers/acl`).respond({
roles: [
{role: {name: 'foo'}},
{role: {name: 'bar'}},
{role: {name: 'baz'}}
]
});
2018-01-04 06:56:26 +00:00
aclService = _aclService_;
aclService.load();
$httpBackend.flush();
2018-01-04 06:56:26 +00:00
}));
describe('load()', () => {
it('should load roles from backend', () => {
expect(aclService.roles).toEqual({
foo: true,
bar: true,
baz: true
});
});
2018-01-04 06:56:26 +00:00
});
describe('hasAny()', () => {
it('should return true when user has any of the passed roles', () => {
let hasAny = aclService.hasAny(['foo', 'nonExistent']);
2018-01-04 06:56:26 +00:00
expect(hasAny).toBeTruthy();
});
2018-01-04 06:56:26 +00:00
it('should return true when user has all the passed roles', () => {
let hasAny = aclService.hasAny(['bar', 'baz']);
2018-01-04 06:56:26 +00:00
expect(hasAny).toBeTruthy();
});
2018-01-04 06:56:26 +00:00
2019-11-12 08:24:08 +00:00
it('should return false when user has not any of the passed roles', () => {
let hasAny = aclService.hasAny(['inventedRole', 'nonExistent']);
2018-01-04 06:56:26 +00:00
expect(hasAny).toBeFalsy();
});
2018-01-04 06:56:26 +00:00
});
describe('reset()', () => {
it('should reset the roles', () => {
aclService.reset();
2018-01-04 06:56:26 +00:00
expect(aclService.roles).toBeNull();
});
2018-01-04 06:56:26 +00:00
});
});