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

49 lines
1.8 KiB
JavaScript

describe('Service acl', () => {
let aclService;
beforeEach(ngModule('vnCore'));
beforeEach(ngModule($provide => {
$provide.value('aclConstant', {});
}));
beforeEach(inject(_aclService_ => {
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);
});
});