diff options
author | HampusM <hampus@hampusmat.com> | 2021-08-06 22:23:46 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-08-06 22:23:46 +0200 |
commit | b2152da8f4bea1a655f7c9c7c07b24c041173f0a (patch) | |
tree | 94022e7a6a94360e8a6c8bfbc7287262cb5a0d15 /test/unit | |
parent | d978be0a3bbf650cd55543570ed18fcb015fc08d (diff) |
Added a tree entry test
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/tree_entry.unit.test.ts | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/unit/tree_entry.unit.test.ts b/test/unit/tree_entry.unit.test.ts new file mode 100644 index 0000000..570ba0f --- /dev/null +++ b/test/unit/tree_entry.unit.test.ts @@ -0,0 +1,83 @@ +import { BaseTreeEntry, BlobTreeEntry, TreeEntry } from "server/src/git/tree_entry"; +import { Repository } from "server/src/git/repository"; +import { EnvironmentVariables } from "../util"; +import { Commit } from "server/src/git/commit"; +import { Tree } from "server/src/git/tree"; +import { Blob } from "../../packages/server/src/git/blob"; + +const env = process.env as EnvironmentVariables; + +describe("Tree entry", () => { + describe("Base tree entry", () => { + describe("Class methods", () => { + let tree_entry: BaseTreeEntry; + + beforeAll(async() => { + const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const tree = await repository.tree(); + tree_entry = tree.entries()[0]; + }); + + it("Should get the latest commit", async() => { + expect.assertions(2); + + const latest_commit = await tree_entry.latestCommit(); + + expect(latest_commit).toBeDefined(); + expect(latest_commit).toBeInstanceOf(Commit); + }); + }); + + }); + + describe("Tree entry", () => { + describe("Class methods", () => { + let tree_entry: BaseTreeEntry; + + beforeAll(async() => { + const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const tree = await repository.tree(); + const entry = tree.entries().find(entry => entry.path === "test"); + if(!entry) { + throw(new Error("Couldn't find the test directory!")); + } + + tree_entry = entry; + }); + + it("Should get the tree", async() => { + expect.assertions(2); + + const entry = tree_entry as TreeEntry; + + const tree = await entry.tree(); + + expect(tree).toBeDefined(); + expect(tree).toBeInstanceOf(Tree); + }); + }); + }); + + describe("Blob tree entry", () => { + describe("Class methods", () => { + let tree_entry: BaseTreeEntry; + + beforeAll(async() => { + const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const tree = await repository.tree(); + tree_entry = tree.entries()[0]; + }); + + it("Should get the blob", async() => { + expect.assertions(2); + + const entry = tree_entry as BlobTreeEntry; + + const blob = await entry.blob(); + + expect(blob).toBeDefined(); + expect(blob).toBeInstanceOf(Blob); + }); + }); + }); +}); |