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

59 lines
1.6 KiB
JavaScript

describe('Service acl', () => {
let aclService;
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(inject((_aclService_, $httpBackend) => {
$httpBackend.when('GET', `/api/Accounts/acl`).respond({
roles: [
{role: {name: 'foo'}},
{role: {name: 'bar'}},
{role: {name: 'baz'}}
]
});
aclService = _aclService_;
aclService.load();
$httpBackend.flush();
}));
describe('load()', () => {
it('should load roles from backend', () => {
expect(aclService.roles).toEqual({
foo: true,
bar: true,
baz: true
});
});
});
describe('hasAny()', () => {
it('should return true when user has any of the passed roles', () => {
let hasAny = aclService.hasAny(['foo', 'nonExistent']);
expect(hasAny).toBeTruthy();
});
it('should return true when user has all the passed roles', () => {
let hasAny = aclService.hasAny(['bar', 'baz']);
expect(hasAny).toBeTruthy();
});
it('should return true when user has not any of the passed roles', () => {
let hasAny = aclService.hasAny(['inventedRole', 'nonExistent']);
expect(hasAny).toBeFalsy();
});
});
describe('reset()', () => {
it('should reset the roles', () => {
aclService.reset();
expect(aclService.roles).toBeNull();
});
});
});