diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-27 16:51:54 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-27 16:51:54 +0200 |
commit | 055a58e79fb225978d64a3c8e3e25377cc2a5ece (patch) | |
tree | 8c37c249b93dfeb507afbf6b156955c96ad3bd49 /test/unit/branch.unit.test.ts | |
parent | fa44d81b658024685e0496150d66a51f2f5fda8c (diff) |
Added new unit tests & the test setup script uses Nodegit instead of exec
Diffstat (limited to 'test/unit/branch.unit.test.ts')
-rw-r--r-- | test/unit/branch.unit.test.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/unit/branch.unit.test.ts b/test/unit/branch.unit.test.ts new file mode 100644 index 0000000..3f067a8 --- /dev/null +++ b/test/unit/branch.unit.test.ts @@ -0,0 +1,60 @@ +import { Branch } from "../../packages/server/src/git/branch"; +import { Repository } from "../../packages/server/src/git/repository"; +import { EnvironmentVariables } from "../util"; + +const env = process.env as EnvironmentVariables; + +describe("Branch", () => { + describe("Class methods", () => { + it("Should lookup a branch", async() => { + expect.assertions(2); + + const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const branch = await Branch.lookup(repository, "master"); + + expect(branch).toBeDefined(); + expect(branch).toBeInstanceOf(Branch); + }); + + it("Should lookup if an existent branch exists and respond true", async() => { + expect.assertions(2); + + const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const branch_exists = await Branch.lookupExists(repository.ng_repository, "master"); + + expect(branch_exists).toBeDefined(); + expect(branch_exists).toBeTruthy(); + }); + + it("Should lookup if an nonexistent branch exists and respond false", async() => { + expect.assertions(2); + + const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + const branch_exists = await Branch.lookupExists(repository.ng_repository, "wubbalubbadubdub"); + + expect(branch_exists).toBeDefined(); + expect(branch_exists).toBeFalsy(); + }); + }); + + describe("Instance methods", () => { + let branch: Branch; + + beforeAll(async() => { + const repository = await Repository.open(env.BASE_DIR, env.AVAIL_REPO); + + branch = await Branch.lookup(repository, "master"); + }); + + it("Should get the latest commit", async() => { + expect.assertions(4); + + const latest_commit = await branch.latestCommit(); + + expect(latest_commit).toBeDefined(); + expect(latest_commit).toHaveProperty("id"); + expect(latest_commit).toHaveProperty("message"); + expect(latest_commit).toHaveProperty("date"); + }); + }); +});
\ No newline at end of file |