49 lines
1.8 KiB
JavaScript
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 hasAny() 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, 'hasAny').and.callThrough();
|
|
|
|
expect(aclService.routeHasPermission(route)).toBeFalsy();
|
|
expect(aclService.hasAny).toHaveBeenCalledWith(route.acl);
|
|
});
|
|
|
|
it('should call the service hasAny() 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, 'hasAny').and.callThrough();
|
|
|
|
expect(aclService.routeHasPermission(route)).toBeTruthy();
|
|
expect(aclService.hasAny).toHaveBeenCalledWith(route.acl);
|
|
});
|
|
});
|