aboutsummaryrefslogtreecommitdiff
path: root/test/unit/commit.unit.test.ts
blob: 5c4d8c74a1bc7b139c67250aa7db43da371366c5 (plain)
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
import { Repository } from "server/src/git/repository";
import { Commit } from "server/src/git/commit";
import { EnvironmentVariables, expectCommitProperties } from "../util";
import { Diff } from "server/src/git/diff";
import { Tree } from "server/src/git/tree";

const env = process.env as EnvironmentVariables;

jest.setTimeout(10000);

describe("Commit", () => {
	let repository: Repository;

	beforeAll(async () => {
		repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO);
	});

	it("Looks up a commit", async () => {
		expect.assertions(8);

		const commit = await Commit.lookup(repository, env.AVAIL_COMMIT);

		expect(commit).toBeDefined();
		expect(commit).toBeInstanceOf(Commit);

		expectCommitProperties(commit);
	});

	it("Looks up a nonexistant commit and throws", async () => {
		expect.assertions(1);

		await expect(Commit.lookup(repository, env.UNAVAIL_COMMIT)).rejects.toThrow();
	});

	it("Looks up if an commit that exists exist", async () => {
		expect.assertions(1);

		await expect(Commit.lookupExists(repository, env.AVAIL_COMMIT)).resolves.toBeTruthy();
	});

	it("Looks up if an nonexistant commit exists", async () => {
		expect.assertions(1);

		await expect(Commit.lookupExists(repository, env.UNAVAIL_COMMIT)).resolves.toBeFalsy();
	});

	describe("Methods", () => {
		let commit: Commit;

		beforeAll(async () => {
			commit = await repository.masterCommit();
		});

		it("Gets 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("Gets the diff", async () => {
			expect.assertions(2);

			const diff = await commit.diff();

			expect(diff).toBeDefined();
			expect(diff).toBeInstanceOf(Diff);
		});
		
		it("Gets the tree", async () => {
			expect.assertions(2);

			const tree = await commit.tree();

			expect(tree).toBeDefined();
			expect(tree).toBeInstanceOf(Tree);
		});
	});	
});