Skip to content

Commit 2cb252c

Browse files
committed
[Added] added testcases for organization
1 parent 14fc01e commit 2cb252c

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

test/routes/organization.test.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import request from "supertest";
2+
import { jest } from "@jest/globals"; // eslint-disable-line import/no-extraneous-dependencies
3+
import app from "#app";
4+
import organizationModel from "#models/organization";
5+
import connector from "#models/databaseUtil";
6+
7+
jest.mock("#util");
8+
9+
let server;
10+
let agent;
11+
12+
beforeAll((done) => {
13+
server = app.listen(null, () => {
14+
agent = request.agent(server);
15+
connector.set("debug", false);
16+
done();
17+
});
18+
});
19+
20+
function cleanUp(callback) {
21+
moduleModel.remove({ startDate: "2023-06-18T14:11:30Z" }).then(() => {
22+
connector.disconnect((DBerr) => {
23+
if (DBerr) {
24+
console.log("Database disconnnect error: ", DBerr);
25+
}
26+
server.close((serverErr) => {
27+
if (serverErr) console.log(serverErr);
28+
callback();
29+
});
30+
});
31+
});
32+
}
33+
34+
afterAll((done) => {
35+
cleanUp(done);
36+
});
37+
38+
describe("Organization API", () => {
39+
it("should create organization", async () => {
40+
const response = await agent.post("/organization/add").send({
41+
parent: "60a0e7e9a09c3f001c834e06",
42+
startDate:"2023-06-18T14:11:30Z",
43+
name:"my org",
44+
accreditations: "60a0e7e9a09c3f001c834e06",
45+
});
46+
47+
expect(response.status).toBe(200);
48+
expect(response.body.res).toMatch(/added organization/);
49+
});
50+
51+
describe("after adding organization", () => {
52+
let id;
53+
beforeEach(async () => {
54+
id = await agent.post("/organization/add").send({
55+
parent: "60a0e7e9a09c3f001c834e06",
56+
startDate:"2023-06-18T14:11:30Z",
57+
name:"my org",
58+
accreditations: "60a0e7e9a09c3f001c834e06",
59+
});
60+
id = JSON.parse(id.res.text).id;
61+
});
62+
63+
afterEach(async () => {
64+
await organizationModel.remove({
65+
parent: "60a0e7e9a09c3f001c834e06",
66+
startDate:"2023-06-18T14:11:30Z",
67+
name:"my org",
68+
accreditations: "60a0e7e9a09c3f001c834e06",
69+
});
70+
});
71+
72+
it("should read organization", async () => {
73+
const response = await agent
74+
.get("/organization/list")
75+
.send({ name:"my org" });
76+
expect(response.status).toBe(200);
77+
expect(response.body.res).toBeDefined();
78+
});
79+
80+
it("should update organization", async () => {
81+
const response = await agent
82+
.post(`/organization/update/${id}`)
83+
.send({ name: "your org" });
84+
85+
expect(response.status).toBe(200);
86+
expect(response.body.res).toMatch(/updated organization/);
87+
});
88+
});
89+
});

0 commit comments

Comments
 (0)