-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from Giveth/add-tests
add get projects tests
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |