forked from OSS-Docs-Tools/code-owner-self-merge
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
55 lines (47 loc) · 2.41 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
const { getFilesNotOwnedByCodeOwner, findCodeOwnersForChangedFiles, githubLoginIsInCodeowners } = 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);
});
})