diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-06 21:30:23 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-06 21:30:23 +0200 |
commit | 7e645f4411bc0b04b909e4534a3c4baaca456629 (patch) | |
tree | 49067124278c5347c72a9f7c831b44f56c3c951b /test | |
parent | 79e9323e92437a3ae564a2bb6ebffe4bc2b21bb3 (diff) |
Added tests
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/commit.unit.test.ts | 74 | ||||
-rw-r--r-- | test/unit/repository.unit.test.ts | 85 |
2 files changed, 159 insertions, 0 deletions
diff --git a/test/unit/commit.unit.test.ts b/test/unit/commit.unit.test.ts new file mode 100644 index 0000000..c4bb6f8 --- /dev/null +++ b/test/unit/commit.unit.test.ts @@ -0,0 +1,74 @@ + +import { Repository } from "server/src/git/repository"; +import { Commit } from "server/src/git/commit"; + +describe("Commit", () => { + const base_dir = "/home/hampus/Projects"; + + let repository: Repository; + + beforeAll(async () => { + repository = await Repository.open(base_dir, "githermit"); + }); + + test("Lookup a existing commit by id", async () => { + const id = "d546492f4fd400ae61a6abbe1905fdbc67451c4d"; + + const lookupCommit = jest.fn(() => Commit.lookup(repository, id)); + + const commit = await lookupCommit(); + + expect(lookupCommit).toReturn(); + expect(commit.id).toBe(id); + }); + + test("Lookup a nonexistant commit by id throws", async () => { + const id = "a546392f4fd440ae61a6afec1d25fdbc67251e2b"; + + expect(Commit.lookup(repository, id)).rejects.toThrow(); + }); + + test("Lookup if an existing commit exists by id", async () => { + const id = "d546492f4fd400ae61a6abbe1905fdbc67451c4d"; + + expect(Commit.lookupExists(repository, id)).resolves.toBeTruthy(); + }); + + test("Lookup if an nonexistant commit exists by id", async () => { + const id = "a546392f4fd440ae61a6afec1d25fdbc67251e2b"; + + expect(Commit.lookupExists(repository, id)).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(); + }); + }); +});
\ No newline at end of file diff --git a/test/unit/repository.unit.test.ts b/test/unit/repository.unit.test.ts new file mode 100644 index 0000000..0e13a2a --- /dev/null +++ b/test/unit/repository.unit.test.ts @@ -0,0 +1,85 @@ +import { Repository } from "server/src/git/repository"; + +describe("Repository", () => { + const base_dir = "/home/hampus/Projects"; + + test("Open existing repository", async () => { + const openRepository = jest.fn(() => Repository.open(base_dir, "githermit")); + + await openRepository(); + + expect(openRepository).toReturn(); + }); + + test("Open nonexistant repository throws", async () => { + expect(Repository.open(base_dir, "angular")).rejects.toThrow(); + }); + + test("Open all repositories", async () => { + const openAllRepositories = jest.fn(() => Repository.openAll(base_dir)); + + await openAllRepositories(); + + expect(openAllRepositories).toReturn(); + }); + + describe("Functions", () => { + let repository: Repository; + + beforeAll(async () => { + repository = await Repository.open(base_dir, "githermit"); + }); + + test("Lookup if an existing object exists", async () => { + const exists = await repository.lookupExists("16778756fb25808a1311403590cd7d36fbbeee6c"); + + expect(exists).toBeTruthy(); + }); + + test("Lookup if an nonexistant object exists", async () => { + const exists = await repository.lookupExists("601747563bff808a1d12403690cd7d36fbbeafcc"); + + expect(exists).toBeFalsy(); + }); + + test("Get latest commit", async () => { + const getLatestCommit = jest.fn(() => repository.latestCommit()); + + await getLatestCommit(); + + expect(getLatestCommit).toReturn(); + }); + + test("Get commits", async () => { + const getCommits = jest.fn(() => repository.commits()); + + await getCommits(); + + expect(getCommits).toReturn(); + }); + + test("Get tree", async () => { + const getTree = jest.fn(() => repository.tree()); + + await getTree(); + + expect(getTree).toReturn(); + }); + + test("Get branches", async () => { + const getBranches = jest.fn(() => repository.branches()); + + await getBranches(); + + expect(getBranches).toReturn(); + }); + + test("Get tags", async () => { + const getTags = jest.fn(() => repository.tags()); + + await getTags(); + + expect(getTags).toReturn(); + }); + }); +});
\ No newline at end of file |