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

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-01-04 06:56:26 +00:00
describe('Service acl', () => {
let aclService;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
2018-01-04 06:56:26 +00:00
beforeEach(inject((_aclService_, $httpBackend) => {
$httpBackend.when('GET', `/api/Accounts/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
it('should return true 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
});
});