diff --git a/client/core/src/lib/specs/aclService.spec.js b/client/core/src/lib/specs/aclService.spec.js new file mode 100644 index 000000000..45a820acc --- /dev/null +++ b/client/core/src/lib/specs/aclService.spec.js @@ -0,0 +1,50 @@ +describe('Service acl', () => { + let aclService; + + beforeEach(() => { + angular.mock.module('vnCore'); + }); + + beforeEach(angular.mock.module($provide => { + $provide.value('aclConstant', {}); + })); + + beforeEach(inject((_aclService_, $httpBackend) => { + 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); + }); +});