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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
import { Repository } from "server/src/git/repository";
import { Commit } from "server/src/git/commit";
import { EnvironmentVariables } from "../util";
import { Diff } from "server/src/git/diff";
import { Tree } from "server/src/git/tree";
const env = process.env as EnvironmentVariables;
describe("Commit", () => {
let repository: Repository;
beforeAll(async() => {
repository = await Repository.open(env.GIT_DIR, env.AVAIL_REPO);
});
describe("Class methods", () => {
it("Should look up a commit", async() => {
expect.assertions(2);
const commit = await Commit.lookup(repository, env.AVAIL_COMMIT);
expect(commit).toBeDefined();
expect(commit).toBeInstanceOf(Commit);
});
it("Should look up a nonexistant commit and throw", async() => {
expect.assertions(1);
await expect(Commit.lookup(repository, env.UNAVAIL_COMMIT)).rejects.toThrow();
});
it("Should look up if an existent commit exists and respond true", async() => {
expect.assertions(1);
await expect(Commit.lookupExists(repository, env.AVAIL_COMMIT)).resolves.toBeTruthy();
});
it("Should look up if an nonexistant commit exists and respond false", async() => {
expect.assertions(1);
await expect(Commit.lookupExists(repository, env.UNAVAIL_COMMIT)).resolves.toBeFalsy();
});
it("Should get multiple commits", async() => {
expect.hasAssertions();
const commits = await Commit.getMultiple(repository);
expect(commits).toBeDefined();
expect(commits).toHaveLength(20);
for(const commit of commits) {
expect(commit).toBeDefined();
expect(commit).toBeInstanceOf(Commit);
}
});
});
describe("Instance methods", () => {
let commit: Commit;
beforeAll(async() => {
commit = await Commit.lookup(repository, "8feb65c5467cc3ad48270183113a121c4a9f86ca");
});
it("Should get the stats", async() => {
expect.assertions(4);
const stats = await commit.stats();
expect(stats).toBeDefined();
expect(stats).toHaveProperty("insertions");
expect(stats).toHaveProperty("deletions");
expect(stats).toHaveProperty("files_changed");
});
it("Should get the diff", async() => {
expect.assertions(2);
const diff = await commit.diff();
expect(diff).toBeDefined();
expect(diff).toBeInstanceOf(Diff);
});
it("Should get the tree", async() => {
expect.assertions(2);
const tree = await commit.tree();
expect(tree).toBeDefined();
expect(tree).toBeInstanceOf(Tree);
});
it("Should get if it's signed and respond true", async() => {
expect.assertions(2);
const is_signed = await commit.isSigned();
expect(is_signed).toBeDefined();
expect(is_signed).toBeTruthy();
});
it("Should get if a unsigned commit is signed and respond false", async() => {
expect.assertions(2);
const other_commit = await Commit.lookup(repository, "7578c24113ba71d7435a94c649566e4e39e0e88c");
const is_signed = await other_commit.isSigned();
expect(is_signed).toBeDefined();
expect(is_signed).toBeFalsy();
});
it("Should get the author", async() => {
expect.assertions(7);
const author = await commit.author();
expect(author).toBeDefined();
expect(author).toHaveProperty("name");
expect(author.name).toBeDefined();
expect(author).toHaveProperty("email");
expect(author.email).toBeDefined();
expect(author).toHaveProperty("fingerprint");
const fingerprint = await author.fingerprint();
expect(fingerprint).toBeDefined();
});
it("Should verify the commit pgp signature and respond true", async() => {
expect.assertions(2);
const verified = await commit.verifySignature();
expect(verified).toBeDefined();
expect(verified).toBeTruthy();
});
});
});
|