From 43995c4be497ea07abf7a8abd7e128c36a830b71 Mon Sep 17 00:00:00 2001 From: Cherik Date: Thu, 2 May 2024 12:10:50 +0330 Subject: [PATCH 1/3] add get projects test --- src/test/getProject.test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/getProject.test.ts diff --git a/src/test/getProject.test.ts b/src/test/getProject.test.ts new file mode 100644 index 0000000..f748700 --- /dev/null +++ b/src/test/getProject.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, test, afterAll } from "@jest/globals"; +import { closeConnection, getCtx } from "./utils"; +import { getProject } from "../controllers/utils/modelHelper"; +import { Project } from "../model"; + +describe("get project", () => { + afterAll(async () => { + await closeConnection(); + }); + + test("handles non-existent projects", async () => { + const ctx = await getCtx(); + const id = "giveth-1"; + const project = await getProject(ctx, "giveth", "1"); + expect(project).toBeDefined(); + expect(project?.id).toBe(id); + }); + + test("fetches an existing project", async () => { + const ctx = await getCtx(); + const id = "giveth-1"; + let _project: Project | undefined = await ctx.store.get(Project, id); + const project = await getProject(ctx, "giveth", "1"); + + expect(_project).toBeDefined(); + expect(project).toBeDefined(); + expect(project?.id).toBe(_project?.id); + }); +}); From a2149eded89560c9bca20079a7bdb47dbdc6bbbd Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Thu, 2 May 2024 13:09:52 +0330 Subject: [PATCH 2/3] Updated tests --- src/test/getProject.test.ts | 9 ++++++++- src/test/store.test.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/test/getProject.test.ts b/src/test/getProject.test.ts index f748700..81b5a8b 100644 --- a/src/test/getProject.test.ts +++ b/src/test/getProject.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test, afterAll } from "@jest/globals"; -import { closeConnection, getCtx } from "./utils"; +import { closeConnection, getCtx, getEntityManager } from "./utils"; import { getProject } from "../controllers/utils/modelHelper"; import { Project } from "../model"; @@ -8,6 +8,11 @@ describe("get project", () => { await closeConnection(); }); + beforeEach(async () => { + const em = await getEntityManager(); + await em.delete(Project, {}); + }); + test("handles non-existent projects", async () => { const ctx = await getCtx(); const id = "giveth-1"; @@ -19,6 +24,8 @@ describe("get project", () => { test("fetches an existing project", async () => { const ctx = await getCtx(); const id = "giveth-1"; + // create a project manually + await getProject(ctx, "giveth", "1"); let _project: Project | undefined = await ctx.store.get(Project, id); const project = await getProject(ctx, "giveth", "1"); diff --git a/src/test/store.test.ts b/src/test/store.test.ts index da3abac..c0645ac 100644 --- a/src/test/store.test.ts +++ b/src/test/store.test.ts @@ -2,7 +2,7 @@ import { describe, expect, test, afterAll } from "@jest/globals"; import { closeConnection, getCtx } from "./utils"; import { Organisation } from "../model"; -describe("simple storage", () => { +describe.skip("simple storage", () => { afterAll(async () => { await closeConnection(); }); From 5fd17e320d31c811770aba617f9d81f711950b09 Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Wed, 15 May 2024 16:21:51 +0330 Subject: [PATCH 3/3] Make the test compatible with develop --- src/test/getProject.test.ts | 8 ++++---- src/test/store.test.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/getProject.test.ts b/src/test/getProject.test.ts index 81b5a8b..0c617b7 100644 --- a/src/test/getProject.test.ts +++ b/src/test/getProject.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test, afterAll } from "@jest/globals"; -import { closeConnection, getCtx, getEntityManager } from "./utils"; +import { closeConnection, getTestCtx, getTestEntityManager } from "./utils"; import { getProject } from "../controllers/utils/modelHelper"; import { Project } from "../model"; @@ -9,12 +9,12 @@ describe("get project", () => { }); beforeEach(async () => { - const em = await getEntityManager(); + const em = await getTestEntityManager(); await em.delete(Project, {}); }); test("handles non-existent projects", async () => { - const ctx = await getCtx(); + const ctx = await getTestCtx(); const id = "giveth-1"; const project = await getProject(ctx, "giveth", "1"); expect(project).toBeDefined(); @@ -22,7 +22,7 @@ describe("get project", () => { }); test("fetches an existing project", async () => { - const ctx = await getCtx(); + const ctx = await getTestCtx(); const id = "giveth-1"; // create a project manually await getProject(ctx, "giveth", "1"); diff --git a/src/test/store.test.ts b/src/test/store.test.ts index 1c1d2aa..4d4ac09 100644 --- a/src/test/store.test.ts +++ b/src/test/store.test.ts @@ -2,7 +2,7 @@ import { describe, expect, test, afterAll } from "@jest/globals"; import { closeConnection, getTestCtx } from "./utils"; import { Organisation } from "../model"; -describe.skip("simple storage", () => { +describe("simple storage", () => { afterAll(async () => { await closeConnection(); });