salix/client/core/src/lib/specs/acl-service.spec.js

51 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-01-04 06:56:26 +00:00
describe('Service acl', () => {
let aclService;
beforeEach(() => {
angular.mock.module('vnCore');
});
beforeEach(angular.mock.module($provide => {
$provide.value('aclConstant', {});
}));
2018-08-30 14:15:30 +00:00
beforeEach(inject(_aclService_ => {
2018-01-04 06:56:26 +00:00
aclService = _aclService_;
}));
it("should return false as the service doesn't have roles", () => {
expect(aclService.routeHasPermission('http://www.verdnatura.es')).toBeFalsy();
});
it("should return true as the service has roles but the route has no acl", () => {
aclService.roles = {customer: true};
expect(aclService.routeHasPermission('http://www.verdnatura.es')).toBeTruthy();
});
it("should return false as the service roles have no length", () => {
aclService.roles = {};
let route = {url: 'http://www.verdnatura.es', acl: []};
expect(aclService.routeHasPermission(route)).toBeFalsy();
});
it("should call the service aclPermission() function and return false as the service has roles and the rote has acl without length", () => {
aclService.roles = {customer: true, employee: true};
let route = {url: 'http://www.verdnatura.es', acl: []};
spyOn(aclService, 'aclPermission').and.callThrough();
expect(aclService.routeHasPermission(route)).toBeFalsy();
expect(aclService.aclPermission).toHaveBeenCalledWith(route.acl);
});
it("should call the service aclPermission() function to return true as the service has roles matching with the ones in acl", () => {
aclService.roles = {customer: true, employee: true};
let route = {url: 'http://www.verdnatura.es', acl: ['customer']};
spyOn(aclService, 'aclPermission').and.callThrough();
expect(aclService.routeHasPermission(route)).toBeTruthy();
expect(aclService.aclPermission).toHaveBeenCalledWith(route.acl);
});
});