-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathrole-schema.test.ts
83 lines (69 loc) · 2.05 KB
/
role-schema.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { roleSchema } from './role-schema';
test('role schema rejects a role without a name', async () => {
expect.assertions(1);
const role = {
permissions: [],
};
try {
await roleSchema.validateAsync(role);
} catch (error) {
expect(error.details[0].message).toBe('"name" is required');
}
});
test('role schema allows a role with an empty description', async () => {
const role = {
name: 'Brønsted',
description: '',
};
const value = await roleSchema.validateAsync(role);
expect(value.description).toEqual('');
});
test('role schema rejects a role with a broken permission list', async () => {
expect.assertions(1);
const role = {
name: 'Mendeleev',
permissions: [
{
aPropertyThatIsAproposToNothing: true,
},
],
};
try {
await roleSchema.validateAsync(role);
} catch (error) {
expect(error.details[0].message).toBe(
'"permissions[0]" must contain at least one of [id, name]',
);
}
});
test('role schema allows a role with an empty permission list', async () => {
const role = {
name: 'Avogadro',
permissions: [],
};
const value = await roleSchema.validateAsync(role);
expect(value.permissions).toEqual([]);
});
test('role schema allows a role with a null list', async () => {
const role = {
name: 'Curie',
permissions: null,
};
const value = await roleSchema.validateAsync(role);
expect(value.permissions).toEqual(null);
});
test('role schema allows an undefined with a null list', async () => {
const role = {
name: 'Fischer',
};
const value = await roleSchema.validateAsync(role);
expect(value.permissions).toEqual(undefined);
});
test('role schema strips roleType if present', async () => {
const role = {
name: 'Grignard',
roleType: 'Organic Chemistry',
};
const value = await roleSchema.validateAsync(role);
expect(value.roleType).toEqual(undefined);
});