Skip to content

Commit

Permalink
add filter test
Browse files Browse the repository at this point in the history
  • Loading branch information
onury committed Nov 9, 2016
1 parent b55b0e4 commit f24b084
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/ac.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,39 @@ describe('Test Suite: Access Control (core)', function () {

});

it('should filter granted attributes', function () {
var ac = this.ac,
attrs = ['*', '!account.balance.credit', '!account.id', '!secret'],
data = {
name: 'Company, LTD.',
address: {
city: 'istanbul',
country: 'TR'
},
account: {
id: 33,
taxNo: 12345,
balance: {
credit: 100,
deposit: 0
}
},
secret: {
value: 'hidden'
}
};
ac.grant('user').createOwn('company', attrs);
var permission = ac.can('user').createOwn('company');
expect(permission.granted).toEqual(true);
var filtered = permission.filter(data);
expect(filtered.name).toEqual(jasmine.any(String));
expect(filtered.address).toEqual(jasmine.any(Object));
expect(filtered.address.city).toEqual('istanbul');
expect(filtered.account).toBeDefined();
expect(filtered.account.id).toBeUndefined();
expect(filtered.account.balance).toBeDefined();
expect(filtered.account.credit).toBeUndefined();
expect(filtered.secret).toBeUndefined();
});

});

0 comments on commit f24b084

Please sign in to comment.