Skip to content

Commit 3fa8509

Browse files
Merge pull request #393 from tcet-opensource/293-Write-testcases-for-students
293 write testcases for students
2 parents 4ef8f2e + bd05981 commit 3fa8509

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

test/routes/student.test.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { jest } from "@jest/globals";
2+
import connector from "#models/databaseUtil";
3+
import studentModel from "#models/student";
4+
5+
jest.mock("#util");
6+
const { agent } = global;
7+
8+
function cleanUp(callback) {
9+
studentModel
10+
.remove({
11+
ERPID: "S1032220999",
12+
name: "Arya",
13+
joiningYear: 2020,
14+
branch: "64fc3c8bde9fa947ea1f412f",
15+
division: "A",
16+
rollNo: 12,
17+
coursesOpted: "64fc3c8bde9fa947ea1f412f",
18+
})
19+
.then(() => {
20+
connector.disconnect((DBerr) => {
21+
if (DBerr) console.log("Database disconnect error : ", DBerr);
22+
callback();
23+
});
24+
});
25+
}
26+
27+
28+
afterAll((done) => {
29+
cleanUp(done);
30+
});
31+
32+
describe("Student API", () => {
33+
it("should create student", async () => {
34+
const response = await agent.post("/student/create").send({
35+
ERPID: "S1032220999",
36+
name: "Arya",
37+
joiningYear: 2020,
38+
branch: "64fc3c8bde9fa947ea1f412f",
39+
division: "A",
40+
rollNo: 12,
41+
coursesOpted: "64fc3c8bde9fa947ea1f412f",
42+
});
43+
44+
expect(response.status).toBe(200);
45+
expect(response.body.res).toMatch(/added user/);
46+
});
47+
48+
describe("after adding student", () => {
49+
let id;
50+
beforeEach(async () => {
51+
id = await agent.post("/student/create").send({
52+
ERPID: "S1032220999",
53+
name: "Arya",
54+
joiningYear: 2020,
55+
branch: "64fc3c8bde9fa947ea1f412f",
56+
division: "A",
57+
rollNo: 12,
58+
coursesOpted: "64fc3c8bde9fa947ea1f412f",
59+
});
60+
id = JSON.parse(id.res.text).id;
61+
});
62+
63+
afterEach(async () => {
64+
await studentModel.remove({
65+
ERPID: "S1032220999",
66+
name: "Arya",
67+
joiningYear: 2020,
68+
branch: "64fc3c8bde9fa947ea1f412f",
69+
division: "A",
70+
rollNo: 12,
71+
coursesOpted: "64fc3c8bde9fa947ea1f412f",
72+
});
73+
});
74+
75+
it("should read student", async () => {
76+
const response = await agent
77+
.get("/student/list")
78+
.send({ name: "Arya" });
79+
expect(response.status).toBe(200);
80+
expect(response.body.res).toBeDefined();
81+
});
82+
83+
it("should update student", async () => {
84+
const response = await agent
85+
.post(`/student/update/${id}`)
86+
.send({ERPID: "S1032220999"},{ joiningYear: 2021 });
87+
88+
expect(response.status).toBe(200);
89+
expect(response.body.res).toMatch(`updated Student with id ${id}`);
90+
});
91+
});
92+
});

0 commit comments

Comments
 (0)