aboutsummaryrefslogtreecommitdiff
path: root/test/unit/commit.unit.test.ts
blob: b8bd178036bb2681c45d883e79d3b923981d3ee2 (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
import { Repository } from "server/src/git/repository";
import { Commit } from "server/src/git/commit";

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

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

	test("Lookup a existing commit by id", async () => {
		const lookupCommit = jest.fn(() => Commit.lookup(repository, process.env.AVAIL_COMMIT));

		const commit = await lookupCommit();

		expect(lookupCommit).toReturn();
		expect(commit.id).toBe(process.env.AVAIL_COMMIT);
	});

	test("Lookup a nonexistant commit by id throws", async () => {
		expect(Commit.lookup(repository, process.env.UNAVAIL_COMMIT)).rejects.toThrow();
	});

	test("Lookup if an existing commit exists by id", async () => {
		expect(Commit.lookupExists(repository, process.env.AVAIL_COMMIT)).resolves.toBeTruthy();
	});

	test("Lookup if an nonexistant commit exists by id", async () => {
		expect(Commit.lookupExists(repository, process.env.UNAVAIL_COMMIT)).resolves.toBeFalsy();
	});

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

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

		test("Get stats", async () => {
			const getStats = jest.fn(() => commit.stats());

			await getStats();

			expect(getStats).toReturn();
		});

		test("Get diff", async () => {
			const getDiff = jest.fn(() => commit.diff());

			await getDiff();

			expect(getDiff).toReturn();
		});
		
		test("Get tree", async () => {
			const getTree = jest.fn(() => commit.tree());

			await getTree();

			expect(getTree).toReturn();
		});
	});	
});