-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathpermission.test.ts
45 lines (35 loc) · 1.25 KB
/
permission.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Permission from '../Permission';
describe('Permission unit test', () => {
const permExample = {
'read': ['data1', 'data2'],
'write': ['data2']
}
const permission = new Permission();
test('Load permission from JSON object', () => {
const s = JSON.stringify(permExample);
permission.load(permExample);
const t = permission.getPermissionJsonObject();
expect(t).toMatchObject(permExample);
})
test('Load permission from JSON string', () => {
const s = JSON.stringify(permExample);
permission.load(s);
const t = permission.getPermissionString();
expect(JSON.parse(t)).toMatchObject(permExample);
})
test('Get targets from an action', () => {
permission.load(permExample);
let expected = permExample['read'];
let actual = permission.getTargetsFromAction('read');
expect(actual.sort()).toEqual(expected.sort());
expected = permExample['write'];
actual = permission.getTargetsFromAction('write');
expect(actual.sort()).toEqual(expected.sort());
})
test('Get action-object mapping', () => {
// TODO
});
test('Get object-action mapping', () => {
// TODO
})
})