Skip to content

Commit 4e788a6

Browse files
fixed issues with the testcase
updated for making sure itll work with the current files
1 parent ecd30fd commit 4e788a6

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

test/routes/practical.test.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest } from "@jest/globals";
1+
import { jest } from "@jest/globals"; // eslint-disable-line import/no-extraneous-dependencies
22
import request from "supertest";
33
import app from "#app"; // Update this import based on your app's structure
44
import connector from "#models/databaseUtil"; // Update this import
@@ -10,7 +10,7 @@ let server;
1010
let agent;
1111

1212
beforeAll((done) => {
13-
server = app.listen(5000, () => {
13+
server = app.listen(null, () => {
1414
agent = request.agent(server);
1515
connector.set("debug", false);
1616
done();
@@ -19,7 +19,7 @@ beforeAll((done) => {
1919

2020
function cleanUp(callback) {
2121
PracticalModel
22-
.deleteMany({})
22+
.remove({})
2323
.then(() => {
2424
connector.disconnect((DBerr) => {
2525
if (DBerr) console.log("Database disconnect error: ", DBerr);
@@ -45,48 +45,42 @@ describe("Practical API", () => {
4545
cognitiveLevels: ["L2", "L3"],
4646
});
4747

48-
expect(response.status).toBe(201);
49-
expect(response.body.res).toMatch(/added user/);
48+
expect(response.status).toBe(200);
49+
expect(response.body.res).toMatch(/Added Practical/);
5050
});
5151

5252
describe("after creating a practical", () => {
5353
let practicalId;
5454

5555
beforeEach(async () => {
56-
const response = await agent.post("/practical/create").send({
57-
no: 1,
58-
title: "Sample Practical",
59-
type: "Experiment",
60-
hours: 2,
61-
cognitiveLevels: ["L2", "L3"],
56+
const id = await agent.post("/practical/create").send({
57+
no: 2,
58+
title: "new practical",
59+
type: "fun experiment",
60+
hours: 5,
61+
cognitiveLevels: ["L1", "L4"],
6262
});
63-
practicalId = response.body.res.match(/(\d+)/)[0];
63+
practicalId = JSON.parse(id.res.text).id;
6464
});
6565

6666
afterEach(async () => {
67-
await PracticalModel.deleteOne({ _id: practicalId });
67+
await PracticalModel.remove();
6868
});
6969

7070
it("should list practical entities", async () => {
71-
const response = await agent.get("/practical/list");
71+
const response = await agent.get("/practical/list")
72+
.send({ title: "new practical" });
7273
expect(response.status).toBe(200);
7374
expect(response.body.res).toHaveLength(1);
7475
});
7576

7677
it("should update a practical entity", async () => {
77-
const response = await agent.post("/practical/update").send({
78-
id: practicalId,
78+
const response = await agent.post(`/practical/update/${practicalId}`).send({
7979
hours: 3,
8080
});
8181

8282
expect(response.status).toBe(200);
83-
expect(response.body.res).toMatch(/updated practical/);
84-
});
85-
86-
it("should delete a practical entity", async () => {
87-
const response = await agent.post(`/practical/delete/${practicalId}`);
88-
expect(response.status).toBe(200);
89-
expect(response.body.res).toMatch(/Deleted practical/);
83+
expect(response.body.res).toMatch(/Updated Practical/);
9084
});
9185
});
9286
});

0 commit comments

Comments
 (0)