-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.test.js
82 lines (73 loc) · 3.39 KB
/
index.test.js
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
const { getFilesNotOwnedByCodeOwner, findCodeOwnersForChangedFiles, githubLoginIsInCodeowners, hasValidLgtmSubstring } = require(".");
test("determine who owns a set of files", () => {
const noFiles = findCodeOwnersForChangedFiles(["root-codeowners/one.two.js"], "./test-code-owners-repo");
expect(noFiles.users).toEqual(["@two"]);
const filesNotInCodeowners = findCodeOwnersForChangedFiles(["root-codeowners/one.two.ts"], "./test-code-owners-repo");
expect(filesNotInCodeowners.users).toEqual([]);
});
test("real world", () => {
const changed = ["/packages/tsconfig-reference/copy/pt/options/files.md"];
const filesNotInCodeowners = findCodeOwnersForChangedFiles(changed, ".");
expect(filesNotInCodeowners.users).toEqual(["@khaosdoctor", "@danilofuchs", "@orta"]);
});
test("real world 2", () => {
const changed = ["/packages/typescriptlang-org/src/copy/pt/index.ts", "/packages/typescriptlang-org/src/copy/pt/nav.ts"];
const filesNotInCodeowners = findCodeOwnersForChangedFiles(changed, ".");
expect(filesNotInCodeowners.users).toEqual(["@khaosdoctor", "@danilofuchs", "@orta"]);
});
test("real world with labels", () => {
// spanish has [] labels in the CODEOWNERS
const changed = ["/packages/typescriptlang-org/src/copy/es/index.ts", "/packages/typescriptlang-org/src/copy/es/nav.ts"];
const filesNotInCodeowners = findCodeOwnersForChangedFiles(changed, ".");
expect(filesNotInCodeowners.labels).toEqual(["translate", "es"]);
});
test("deciding if someone has access to merge", () => {
const noFiles = getFilesNotOwnedByCodeOwner("@two", ["root-codeowners/one.two.js"], "./test-code-owners-repo");
expect(noFiles).toEqual([]);
const filesNotInCodeowners = getFilesNotOwnedByCodeOwner("@two", ["random-path/file.ts"], "./test-code-owners-repo");
expect(filesNotInCodeowners).toEqual(["random-path/file.ts"]);
});
describe(githubLoginIsInCodeowners, () => {
test("allows folks found in the codeowners", () => {
const ortaIn = githubLoginIsInCodeowners("orta", ".");
expect(ortaIn).toEqual(true);
});
test("ignores case", () => {
const ortaIn = githubLoginIsInCodeowners("OrTa", ".");
expect(ortaIn).toEqual(true);
});
test("denies other accounts", () => {
const noDogMan = githubLoginIsInCodeowners("dogman", ".");
expect(noDogMan).toEqual(false);
});
test("denies subsets of existing accounts", () => {
const noOrt = githubLoginIsInCodeowners("ort", ".");
expect(noOrt).toEqual(false);
});
})
describe(hasValidLgtmSubstring, () => {
test("allows lgtm", () => {
const isValidSubstring = hasValidLgtmSubstring("this lgtm!");
expect(isValidSubstring).toEqual(true);
});
test("denies lgtm but", () => {
const isValidSubstring = hasValidLgtmSubstring("this lgtm but");
expect(isValidSubstring).toEqual(false);
});
test("denies lgtm but", () => {
const isValidSubstring = hasValidLgtmSubstring("this lgtm, but");
expect(isValidSubstring).toEqual(false);
});
test("denies lgtm in double quotes", () => {
const isValidSubstring = hasValidLgtmSubstring("\"lgtm\"");
expect(isValidSubstring).toEqual(false);
});
test("denies lgtm in single quotes", () => {
const isValidSubstring = hasValidLgtmSubstring("'lgtm");
expect(isValidSubstring).toEqual(false);
});
test("denies lgtm in inline code blocks", () => {
const isValidSubstring = hasValidLgtmSubstring("lgtm`");
expect(isValidSubstring).toEqual(false);
});
})