Skip to content

Commit ba54cf8

Browse files
committed
fixed testcases for attendance
1 parent 91dea20 commit ba54cf8

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import moduleRouter from "#routes/module";
2323
import facultyRouter from "#routes/faculty";
2424
import { identifyUser } from "#middleware/identifyUser";
2525
import departmentRouter from "#routes/department";
26-
import attendenceRouter from "#routes/attendance";
26+
import attendanceRouter from "#routes/attendance";
2727
import examRouter from "#routes/exam";
2828
import paperRouter from "#routes/paper";
2929
import groupRouter from "#routes/group";
@@ -61,7 +61,7 @@ app.use("/timetable", timetableRouter);
6161
app.use("/department", departmentRouter);
6262
app.use("/coursework", courseworkRouter);
6363
app.use("/module", moduleRouter);
64-
app.use("/attendence", attendenceRouter);
64+
app.use("/attendance", attendanceRouter);
6565
app.use("/exam", examRouter);
6666
app.use("/paper", paperRouter);
6767
app.use("/group", groupRouter);

services/attendance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function addNewAttendance( student, course, monthlyAttended, monthl
1010
cumulativeAttended,
1111
cumulativeOccured,
1212
});
13-
if (newAttendance.student === student) {
13+
if (String(newAttendance.student) === student) {
1414
return newAttendance;
1515
}
1616
throw new databaseError.DataEntryError("Add Attendance");

test/routes/attendance.test.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
import request from "supertest";
21
import { jest } from "@jest/globals"; // eslint-disable-line import/no-extraneous-dependencies
3-
import app from "#app";
42
import attendanceModel from "#models/attendance";
53
import connector from "#models/databaseUtil";
64

75
jest.mock("#util");
8-
9-
let server;
10-
let agent;
11-
beforeAll((done) => {
12-
server = app.listen(null, () => {
13-
agent = request.agent(server);
14-
connector.set("debug", false);
15-
done();
16-
});
17-
});
6+
const { agent } = global;
187

198
function cleanUp(callback) {
20-
attendanceModel.remove({ student: "xyz" }).then(() => {
9+
attendanceModel.remove({ student: "64fc3c8bde9fa947ea1f412f" }).then(() => {
2110
connector.disconnect((DBerr) => {
2211
if (DBerr) console.log("Database dissconnnect error: ", DBerr);
23-
server.close((serverErr) => {
24-
if (serverErr) console.log(serverErr);
25-
callback();
26-
});
12+
callback();
2713
});
2814
});
2915
}
@@ -35,8 +21,8 @@ afterAll((done) => {
3521
describe("checking attendance functions", () => {
3622
it("create attendance", async () => {
3723
const response = await agent.post("/attendance/add").send({
38-
student: "xyz",
39-
course: "XYZ",
24+
student: "64fc3c8bde9fa947ea1f412f",
25+
course: "64fc3c8bde9fa947ea1f412f",
4026
monthlyAttended: 123,
4127
monthlyOccured: 123,
4228
cumulativeAttended: 123,
@@ -49,32 +35,32 @@ describe("checking attendance functions", () => {
4935
let id;
5036
beforeEach(async () => {
5137
id = await agent.post("/attendance/add").send({
52-
student: "xyz",
53-
course: "XYZ",
54-
monthlyAttended: 123,
55-
monthlyOccured: 123,
56-
cumulativeAttended: 123,
57-
cumulativeOccured: 123,
38+
student: "64fc3c8bde9fa947ea1f412f",
39+
course: "64fc3c8bde9fa947ea1f412f",
40+
monthlyAttended: 123,
41+
monthlyOccured: 123,
42+
cumulativeAttended: 123,
43+
cumulativeOccured: 123,
5844
});
5945
id = JSON.parse(id.res.text).id;
6046
});
6147

6248
afterEach(async () => {
63-
await attendanceModel.remove({ student: "xyz" });
49+
await attendanceModel.remove({ student: "64fc3c8bde9fa947ea1f412f" });
6450
});
6551

6652
it("read attendance", async () => {
6753
const response = await agent
6854
.get("/attendance/list")
69-
.send({ student: "xyz" });
55+
.send({ student: "64fc3c8bde9fa947ea1f412f" });
7056
expect(response.status).toBe(200);
7157
expect(response.body.res).toBeDefined();
7258
});
7359

7460
it("update attendance", async () => {
7561
const response = await agent
7662
.post(`/attendance/update/${id}`)
77-
.send({ student: "xyz" }, { student: "123" });
63+
.send({ student: "64fc3c8bde9fa947ea1f412f" });
7864
expect(response.headers["content-type"]).toMatch(/json/);
7965
expect(response.status).toBe(200);
8066
expect(response.body.res).toMatch(/attendance updated/);

0 commit comments

Comments
 (0)