-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
75 lines (70 loc) · 2.07 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
const {
repoOwner,
repoName,
correctBranch,
wrongBranch,
} = require("./test.common.js");
const {
init,
createCommitOnBranch,
checkIfBranchExists,
getShaOfParentCommit,
} = require("./index");
init();
describe("createCommitOnBranch", () => {
test("createCommitOnBranch, good branch", async () => {
const result = await createCommitOnBranch(
repoOwner,
repoName,
correctBranch,
["dummy/file1.txt", "dummy/file2.txt"], // added files
[], // deleted files
"this is a commit msg",
"the description of the commit"
);
//console.log(JSON.stringify(result, null, 2));
const commitUrl = result?.commitUrl || "";
expect(commitUrl).toMatch(
new RegExp(
"^https://github.com/" +
repoOwner +
"/" +
repoName +
"/commit/[a-fA-F0-9]{40}$"
)
);
});
test("createCommitOnBranch, BAD branch", async () => {
expect(async () => {
await createCommitOnBranch(
repoOwner,
repoName,
wrongBranch,
["dummy/file1.txt", "dummy/file1.txt"], // added files
[], // deleted files
"this is a commit msg",
"the description of the commit"
);
}).rejects.toThrow(Error);
});
});
describe("checkIfBranchExists", () => {
test("checkIfBranchExists, good branch", async () => {
const result = await checkIfBranchExists(repoOwner, repoName, correctBranch);
expect(result).toBeTruthy();
});
test("checkIfBranchExists, BAD branch", async () => {
const result = await checkIfBranchExists(repoOwner, repoName, wrongBranch);
expect(result).toBeFalsy();
});
});
describe("getShaOfParentCommit", () => {
test("getShaOfParentCommit, good branch", async () => {
const result = await getShaOfParentCommit(repoOwner, repoName, correctBranch);
expect(result).toMatch(/[a-f0-9]{40}/); // commit hash is 40 characters long
});
test("getShaOfParentCommit, BAD branch", async () => {
const result = await getShaOfParentCommit(repoOwner, repoName, wrongBranch);
expect(result).toBeNull();
});
});