Skip to content

Commit 482aa51

Browse files
committed
Unit tests improved
1 parent 21e92ce commit 482aa51

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

dist/acl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ angular.module('stylet.acl').service('AclService', ["AclRegistryService", functi
492492
this.addRole = function (role, parents) {
493493
parents = typeof parents === 'undefined' ? null : parents;
494494

495+
if (typeof role !== 'string' || role === '') {
496+
throw new Error('addRole() expects role to be a not empty string');
497+
}
498+
495499
_roleRegistry.add(role, parents);
496500

497501
return self;

src/acl-service.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ angular.module('stylet.acl').service('AclService', function (AclRegistryService)
491491
this.addRole = function (role, parents) {
492492
parents = typeof parents === 'undefined' ? null : parents;
493493

494+
if (typeof role !== 'string' || role === '') {
495+
throw new Error('addRole() expects role to be a not empty string');
496+
}
497+
494498
_roleRegistry.add(role, parents);
495499

496500
return self;

test/acl-service.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ describe('ncAclService', function () {
8585

8686
describe('Role management', function () {
8787

88+
it('ensures that basic addition and retrieval of a single Role works', function () {
89+
expect(AclService.getRoles()).toEqual([]);
90+
91+
var role = AclService.addRole('guest').getRole('guest');
92+
93+
expect(role).toEqual('guest');
94+
expect(AclService.getRole('guest')).toEqual('guest');
95+
});
96+
8897
it('ensures that getRoles() method works as expected', function () {
8998
expect(AclService.getRoles()).toEqual([]);
9099

@@ -134,6 +143,21 @@ describe('ncAclService', function () {
134143
expect(AclService.isAllowed('Guest')).toBeFalsy();
135144
});
136145

146+
it('ensures that an exception is thrown when a non-existent Role is specified as a parent upon Role addition', function () {
147+
expect(function() {
148+
AclService.addRole('tst', 'unexisted');
149+
}).toThrow();
150+
});
151+
152+
it('ensures that an exception is thrown when a not Role is passed', function () {
153+
expect(function() {
154+
AclService.addRole({});
155+
}).toThrowError(/expects role to be/);
156+
expect(function() {
157+
AclService.addRole('');
158+
}).toThrowError(/expects role to be/);
159+
});
160+
137161
});
138162

139163
describe('Resource management', function () {

0 commit comments

Comments
 (0)