describe('Service acl', () => { let aclService; beforeEach(ngModule('vnCore')); beforeEach(inject((_aclService_, $httpBackend) => { $httpBackend.when('GET', `VnUsers/acl`).respond({ roles: [ {role: {name: 'foo'}}, {role: {name: 'bar'}}, {role: {name: 'baz'}} ] }); $httpBackend.whenPOST('Accounts/user/acl').respond([ { id: 1, model: 'ModelExample', property: '*', accessType: '*', permission: 'ALLOW', principalType: 'ROLE', principalId: 'employee' } ]); aclService = _aclService_; aclService.load(); $httpBackend.flush(); })); describe('load()', () => { it('should load roles from backend', () => { expect(aclService.roles).toEqual({ foo: true, bar: true, baz: true }); }); }); describe('hasAny()', () => { it('should return true when user has any of the passed roles', () => { let hasAny = aclService.hasAny(['foo', 'nonExistent']); expect(hasAny).toBeTruthy(); }); it('should return true when user has all the passed roles', () => { let hasAny = aclService.hasAny(['bar', 'baz']); expect(hasAny).toBeTruthy(); }); it('should return false when user has not any of the passed roles', () => { let hasAny = aclService.hasAny(['inventedRole', 'nonExistent']); expect(hasAny).toBeFalsy(); }); }); describe('reset()', () => { it('should reset the roles', () => { aclService.reset(); expect(aclService.roles).toBeNull(); }); }); });