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
|
import { Repository } from "server/src/git/repository";
import { Commit } from "server/src/git/commit";
import { Tree } from "server/src/git/tree";
import { Branch } from "server/src/git/branch";
import { Tag } from "server/src/git/tag";
import { EnvironmentVariables, expectCommitProperties } from "../util";
import { BaseError } from "server/src/git/error";
const env = process.env as EnvironmentVariables;
function expectRepositoryProperties(repository: Repository) {
expect(repository).toHaveProperty("base_dir");
expect(repository).toHaveProperty("description");
expect(repository).toHaveProperty("name");
expect(repository).toHaveProperty("name.full");
expect(repository).toHaveProperty("name.short");
expect(repository).toHaveProperty("owner");
}
describe("Repository", () => {
it("Should open a repository", async () => {
expect.assertions(8);
const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO);
expect(repository).toBeDefined();
expect(repository).toBeInstanceOf(Repository);
expectRepositoryProperties(repository);
});
it("Should fail to open a nonexistant repository", async () => {
expect.assertions(1);
await expect(Repository.open(env.BASE_DIR, env.UNAVAIL_REPO)).rejects.toBeInstanceOf(BaseError);
});
it("Should open all repositories", async () => {
expect.hasAssertions();
const all_repositories = await Repository.openAll(env.BASE_DIR);
expect(all_repositories).toBeDefined();
for(const repository of all_repositories) {
expect(repository).toBeDefined();
expect(repository).toBeInstanceOf(Repository)
expectRepositoryProperties(repository);
}
});
describe("Methods", () => {
let repository: Repository;
beforeAll(async () => {
repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO);
});
it("Should look up if an existent object exists and respond true", async () => {
expect.assertions(1);
await expect(repository.lookupExists(env.AVAIL_OBJECT)).resolves.toBeTruthy();
});
it("Should look up if an nonexistant object exists and respond false", async () => {
expect.assertions(1);
await expect(repository.lookupExists(env.UNAVAIL_OBJECT)).resolves.toBeFalsy();
});
it("Should get the master commit", async () => {
expect.assertions(8);
const master_commit = await repository.masterCommit();
expect(master_commit).toBeDefined();
expect(master_commit).toBeInstanceOf(Commit);
expectCommitProperties(master_commit);
});
it("Should get the commits", async () => {
expect.hasAssertions();
const commits = await repository.commits();
expect(commits).toBeDefined();
for(const commit of commits) {
expect(commit).toBeDefined();
expect(commit).toBeInstanceOf(Commit);
expectCommitProperties(commit);
}
});
it("Should get the tree", async () => {
expect.assertions(2);
const tree = await repository.tree();
expect(tree).toBeDefined();
expect(tree).toBeInstanceOf(Tree);
});
it("Should get the branches", async () => {
expect.hasAssertions();
const branches = await repository.branches();
expect(branches).toBeDefined();
for(const branch of branches) {
expect(branch).toBeDefined();
expect(branch).toBeInstanceOf(Branch);
expect(branch).toHaveProperty("id");
expect(branch).toHaveProperty("name");
}
});
it("Should get the tags", async () => {
expect.hasAssertions();
const tags = await repository.tags();
expect(tags).toBeDefined();
for(const tag of tags) {
expect(tag).toBeDefined();
expect(tag).toBeInstanceOf(Tag);
expect(tag).toHaveProperty("id");
expect(tag).toHaveProperty("name");
}
});
});
});
|