Skip to content

Commit 764de07

Browse files
committed
added testcases for tutorial
1 parent 14fc01e commit 764de07

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

test/routes/tutorial.test.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 tutorialModel from "#models/tutorial";
5+
import connector from "#models/databaseUtil";
6+
7+
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+
});
18+
19+
function cleanUp(callback) {
20+
tutorialModel.remove({ no: "123git" }).then(() => {
21+
connector.disconnect((DBerr) => {
22+
if (DBerr) console.log("Database dissconnnect error: ", DBerr);
23+
server.close((serverErr) => {
24+
if (serverErr) console.log(serverErr);
25+
callback();
26+
});
27+
});
28+
});
29+
}
30+
31+
afterAll((done) => {
32+
cleanUp(done);
33+
});
34+
35+
describe("checking tutorial functions", () => {
36+
it("create tutorial", async () => {
37+
const response = await agent.post("/tutorial/add").send({
38+
no: "123",
39+
title: "abc",
40+
hours: "3",
41+
cognitiveLevel: "abc",
42+
});
43+
expect(response.headers["content-type"]).toMatch(/json/);
44+
expect(response.status).toBe(200);
45+
expect(response.body.res).toMatch(/added tutorial/);
46+
});
47+
48+
beforeEach(async () => {
49+
agent.post("/tutorial/add").send({
50+
no: "123",
51+
title: "abc",
52+
hours: "3",
53+
cognitiveLevel: "abc",
54+
});
55+
});
56+
57+
afterEach(async () => {
58+
await tutorialModel.remove({ no: "123" });
59+
});
60+
61+
it("read tutorial", async () => {
62+
const response = await agent
63+
.get("/tutorial/list")
64+
.send({ name: "xyz" });
65+
expect(response.status).toBe(200);
66+
expect(response.body.res).toBeDefined();
67+
});
68+
69+
it("update tutorial", async () => {
70+
const response = await agent
71+
.post("/tutorial/update")
72+
.send({ no: "123" }, { no: "123" });
73+
expect(response.headers["content-type"]).toMatch(/json/);
74+
expect(response.status).toBe(200);
75+
expect(response.body.res).toMatch(/tutorial updated/);
76+
});
77+
});

0 commit comments

Comments
 (0)