Skip to content

Commit f24b084

Browse files
committed
add filter test
1 parent b55b0e4 commit f24b084

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/ac.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,39 @@ describe('Test Suite: Access Control (core)', function () {
373373

374374
});
375375

376+
it('should filter granted attributes', function () {
377+
var ac = this.ac,
378+
attrs = ['*', '!account.balance.credit', '!account.id', '!secret'],
379+
data = {
380+
name: 'Company, LTD.',
381+
address: {
382+
city: 'istanbul',
383+
country: 'TR'
384+
},
385+
account: {
386+
id: 33,
387+
taxNo: 12345,
388+
balance: {
389+
credit: 100,
390+
deposit: 0
391+
}
392+
},
393+
secret: {
394+
value: 'hidden'
395+
}
396+
};
397+
ac.grant('user').createOwn('company', attrs);
398+
var permission = ac.can('user').createOwn('company');
399+
expect(permission.granted).toEqual(true);
400+
var filtered = permission.filter(data);
401+
expect(filtered.name).toEqual(jasmine.any(String));
402+
expect(filtered.address).toEqual(jasmine.any(Object));
403+
expect(filtered.address.city).toEqual('istanbul');
404+
expect(filtered.account).toBeDefined();
405+
expect(filtered.account.id).toBeUndefined();
406+
expect(filtered.account.balance).toBeDefined();
407+
expect(filtered.account.credit).toBeUndefined();
408+
expect(filtered.secret).toBeUndefined();
409+
});
410+
376411
});

0 commit comments

Comments
 (0)