Skip to content

Commit

Permalink
Merge pull request #41 from Giveth/add-tests
Browse files Browse the repository at this point in the history
add get projects tests
  • Loading branch information
aminlatifi authored May 15, 2024
2 parents 2aa87a4 + 5fd17e3 commit 0921930
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/getProject.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, expect, test, afterAll } from "@jest/globals";
import { closeConnection, getTestCtx, getTestEntityManager } from "./utils";
import { getProject } from "../controllers/utils/modelHelper";
import { Project } from "../model";

describe("get project", () => {
afterAll(async () => {
await closeConnection();
});

beforeEach(async () => {
const em = await getTestEntityManager();
await em.delete(Project, {});
});

test("handles non-existent projects", async () => {
const ctx = await getTestCtx();
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 getTestCtx();
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");

expect(_project).toBeDefined();
expect(project).toBeDefined();
expect(project?.id).toBe(_project?.id);
});
});

0 comments on commit 0921930

Please sign in to comment.