aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-22 21:36:10 +0200
committerHampusM <hampus@hampusmat.com>2021-07-22 21:36:10 +0200
commit998d566194cf901a2c927851f9b87c8b577d21a9 (patch)
treedda6c200802598fe5691815b81f4d1d359a1a19b /test
parent827013d79853fb4648b7c7781f9827ec1ca8b5b9 (diff)
Added tree unit tests
Diffstat (limited to 'test')
-rw-r--r--test/unit/tree.unit.test.ts66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/unit/tree.unit.test.ts b/test/unit/tree.unit.test.ts
new file mode 100644
index 0000000..1f66435
--- /dev/null
+++ b/test/unit/tree.unit.test.ts
@@ -0,0 +1,66 @@
+import { Repository } from "server/src/git/repository";
+import { Tree } from "server/src/git/tree";
+import { TreeEntry } from "server/src/git/tree_entry";
+import { BaseError } from "server/src/git/error";
+import { EnvironmentVariables } from "../util";
+
+const env = process.env as EnvironmentVariables;
+
+describe("Tree", () => {
+ it("Should get the tree of a repository", async () => {
+ expect.assertions(2);
+
+ const tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO));
+
+ expect(tree).toBeDefined();
+ expect(tree).toBeInstanceOf(Tree);
+ });
+
+ describe("Methods", () => {
+ let tree: Tree;
+
+ beforeAll(async () => {
+ tree = await Tree.ofRepository(await Repository.open(env.BASE_DIR, env.AVAIL_REPO));
+ });
+
+ it("Should get the entries", () => {
+ expect.hasAssertions();
+
+ const entries = tree.entries();
+
+ expect(entries).toBeDefined();
+
+ for(const entry of entries) {
+ expect(entry).toBeDefined();
+ expect(entry).toBeInstanceOf(TreeEntry);
+ }
+ });
+
+ it("Should return the entry of a path", async () => {
+ expect.assertions(2);
+
+ const entry = await tree.find("packages/server");
+
+ expect(entry).toBeDefined();
+ expect(entry).toBeInstanceOf(Tree);
+ });
+
+ it("Should fail to return the entry of a nonexistent path", async () => {
+ expect.assertions(1);
+
+ await expect(tree.find("dependencies/libstd++")).rejects.toBeInstanceOf(BaseError);
+ });
+
+ it("Should find out if an existent path exists and return true", async () => {
+ expect.assertions(1);
+
+ await expect(tree.findExists("packages/shared_types/package.json")).resolves.toBeTruthy();
+ });
+
+ it("Should find out if a nonexistent path exists and return false", async () => {
+ expect.assertions(1);
+
+ await expect(tree.findExists("packages/core/main.js")).resolves.toBeFalsy();
+ });
+ });
+}); \ No newline at end of file