-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperms.test.ts
50 lines (43 loc) · 1.42 KB
/
perms.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
import { hasPerm } from "./perms.js";
test("should return true if perm is global.*", () => {
const perms = ["global.*"];
const perm = "global.test";
const result = hasPerm(perms, perm);
expect(result).toBe(true);
});
test("should return true if perm is global and perms contains global.*", () => {
const perms = ["global.*", "test"];
const perm = "global.test";
const result = hasPerm(perms, perm);
expect(result).toBe(true);
});
test("should return false if perm is not in perms", () => {
const perms = ["test"];
const perm = "global.test";
const result = hasPerm(perms, perm);
expect(result).toBe(false);
});
test("should return false if perm is in perms with a negator", () => {
const perms = ["~global.test"];
const perm = "global.test";
const result = hasPerm(perms, perm);
expect(result).toBe(false);
});
test("should return true if perm is in perms without a negator", () => {
const perms = ["global.test"];
const perm = "global.test";
const result = hasPerm(perms, perm);
expect(result).toBe(true);
});
test("should return true if perm is in perms with a wildcard", () => {
const perms = ["global.*"];
const perm = "global.test";
const result = hasPerm(perms, perm);
expect(result).toBe(true);
});
test("should return true if perm is in perms with a wildcard and a negator", () => {
const perms = ["~global.*"];
const perm = "global.test";
const result = hasPerm(perms, perm);
expect(result).toBe(true);
});