2018-01-04 06:56:26 +00:00
|
|
|
describe('Service acl', () => {
|
|
|
|
let aclService;
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2018-01-04 06:56:26 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
beforeEach(inject((_aclService_, $httpBackend) => {
|
|
|
|
$httpBackend.when('GET', `/api/Accounts/acl`).respond({
|
|
|
|
roles: [
|
|
|
|
{role: {name: 'foo'}},
|
|
|
|
{role: {name: 'bar'}},
|
|
|
|
{role: {name: 'baz'}}
|
|
|
|
]
|
|
|
|
});
|
2018-01-04 06:56:26 +00:00
|
|
|
aclService = _aclService_;
|
2019-01-23 16:49:28 +00:00
|
|
|
aclService.load();
|
|
|
|
$httpBackend.flush();
|
2018-01-04 06:56:26 +00:00
|
|
|
}));
|
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
describe('load()', () => {
|
|
|
|
it('should load roles from backend', () => {
|
|
|
|
expect(aclService.roles).toEqual({
|
|
|
|
foo: true,
|
|
|
|
bar: true,
|
|
|
|
baz: true
|
|
|
|
});
|
|
|
|
});
|
2018-01-04 06:56:26 +00:00
|
|
|
});
|
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
describe('hasAny()', () => {
|
|
|
|
it('should return true when user has any of the passed roles', () => {
|
|
|
|
let hasAny = aclService.hasAny(['foo', 'nonExistent']);
|
2018-01-04 06:56:26 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
expect(hasAny).toBeTruthy();
|
|
|
|
});
|
2018-01-04 06:56:26 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
it('should return true when user has all the passed roles', () => {
|
|
|
|
let hasAny = aclService.hasAny(['bar', 'baz']);
|
2018-01-04 06:56:26 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
expect(hasAny).toBeTruthy();
|
|
|
|
});
|
2018-01-04 06:56:26 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
it('should return true when user has not any of the passed roles', () => {
|
|
|
|
let hasAny = aclService.hasAny(['inventedRole', 'nonExistent']);
|
2018-01-04 06:56:26 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
expect(hasAny).toBeFalsy();
|
|
|
|
});
|
2018-01-04 06:56:26 +00:00
|
|
|
});
|
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
describe('reset()', () => {
|
|
|
|
it('should reset the roles', () => {
|
|
|
|
aclService.reset();
|
2018-01-04 06:56:26 +00:00
|
|
|
|
2019-01-23 16:49:28 +00:00
|
|
|
expect(aclService.roles).toBeNull();
|
|
|
|
});
|
2018-01-04 06:56:26 +00:00
|
|
|
});
|
|
|
|
});
|