diff options
Diffstat (limited to 'test/unit/commit.unit.test.ts')
-rw-r--r-- | test/unit/commit.unit.test.ts | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/test/unit/commit.unit.test.ts b/test/unit/commit.unit.test.ts index f197583..b37e9cf 100644 --- a/test/unit/commit.unit.test.ts +++ b/test/unit/commit.unit.test.ts @@ -1,5 +1,10 @@ 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); @@ -7,58 +12,73 @@ describe("Commit", () => { let repository: Repository; beforeAll(async () => { - repository = await Repository.open(process.env.BASE_DIR, process.env.AVAIL_REPO); + repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); }); - test("Lookup a existing commit by id", async () => { - const lookupCommit = jest.fn(() => Commit.lookup(repository, process.env.AVAIL_COMMIT)); + it("Looks up a commit", async () => { + expect.assertions(8); + + const commit = await Commit.lookup(repository, env.AVAIL_COMMIT); - const commit = await lookupCommit(); + expect(commit).toBeDefined(); + expect(commit).toBeInstanceOf(Commit); - expect(lookupCommit).toReturn(); - expect(commit.id).toBe(process.env.AVAIL_COMMIT); + expectCommitProperties(commit); }); - test("Lookup a nonexistant commit by id throws", async () => { - expect(Commit.lookup(repository, process.env.UNAVAIL_COMMIT)).rejects.toThrow(); + it("Looks up a nonexistant commit and throws", async () => { + expect.assertions(1); + + await expect(Commit.lookup(repository, 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(); + it("Looks up if an commit that exists exist", async () => { + expect.assertions(1); + + await expect(Commit.lookupExists(repository, 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(); + it("Looks up if an nonexistant commit exists", async () => { + expect.assertions(1); + + await expect(Commit.lookupExists(repository, env.UNAVAIL_COMMIT)).resolves.toBeFalsy(); }); - describe("Functions", () => { + describe("Methods", () => { let commit: Commit; beforeAll(async () => { commit = await repository.latestCommit(); }); - test("Get stats", async () => { - const getStats = jest.fn(() => commit.stats()); - await getStats(); + it("Gets the stats", async () => { + expect.assertions(4); + + const stats = await commit.stats(); + + expect(stats).toBeDefined(); - expect(getStats).toReturn(); + expect(stats).toHaveProperty("insertions"); + expect(stats).toHaveProperty("deletions"); + expect(stats).toHaveProperty("files_changed"); }); - test("Get diff", async () => { - const getDiff = jest.fn(() => commit.diff()); + it("Gets the diff", async () => { + expect.assertions(2); - await getDiff(); + const diff = await commit.diff(); - expect(getDiff).toReturn(); + expect(diff).toBeDefined(); + expect(diff).toBeInstanceOf(Diff); }); - test("Get tree", async () => { - const getTree = jest.fn(() => commit.tree()); + it("Gets the tree", async () => { + expect.assertions(2); - await getTree(); + const tree = await commit.tree(); - expect(getTree).toReturn(); + expect(tree).toBeDefined(); + expect(tree).toBeInstanceOf(Tree); }); }); });
\ No newline at end of file |