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
|
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";
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("Opens a repository successfully", async () => {
expect.assertions(8);
const repository = await Repository.open(process.env.BASE_DIR, env.AVAIL_REPO);
expect(repository).toBeDefined();
expect(repository).toBeInstanceOf(Repository);
expectRepositoryProperties(repository);
});
it("Fails to open a nonexistant repository", async () => {
expect.assertions(1);
await expect(Repository.open(process.env.BASE_DIR, env.UNAVAIL_REPO)).rejects.toThrow();
});
it("Opens 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(process.env.BASE_DIR, env.AVAIL_REPO);
});
it("Looks up if an object that exists exist", async () => {
expect.assertions(1);
await expect(repository.lookupExists(env.AVAIL_OBJECT)).resolves.toBeTruthy();
});
it("Looks up if an nonexistant object exists", async () => {
expect.assertions(1);
await expect(repository.lookupExists(env.UNAVAIL_OBJECT)).resolves.toBeFalsy();
});
it("Gets 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("Gets 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("Gets the tree", async () => {
expect.assertions(2);
const tree = await repository.tree();
expect(tree).toBeDefined();
expect(tree).toBeInstanceOf(Tree);
});
it("Gets 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("Gets 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");
}
});
});
});
|