Skip to content

Commit 2dca36e

Browse files
committed
Merge branch 'development' of https://github.com/tcet-opensource/erp-backend into 251-testcases-for-organisation
2 parents b8123d1 + 77f826f commit 2dca36e

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const config = {
22
transform: {
33
},
4+
"testTimeout": 15000,
45
};
56

67
export default config;

test/routes/tutorial.test.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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: "123" }).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: ["L1"],
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+
describe("after creating a practical", () => {
49+
let tutorialId;
50+
beforeEach(async () => {
51+
const id = await agent.post("/tutorial/add").send({
52+
no: "456",
53+
title: "dfg",
54+
hours: "3",
55+
cognitiveLevel: ["L1", "L2"],
56+
});
57+
tutorialId = JSON.parse(id.res.text).id;
58+
});
59+
60+
afterEach(async () => {
61+
await tutorialModel.remove();
62+
});
63+
64+
it("read tutorial", async () => {
65+
const response = await agent
66+
.get("/tutorial/list")
67+
.send({ name: "dfg" });
68+
expect(response.status).toBe(200);
69+
expect(response.body.res).toBeDefined();
70+
});
71+
72+
it("update tutorial", async () => {
73+
const response = await agent
74+
.post(`/tutorial/update/${tutorialId}`)
75+
.send({ no: "456" });
76+
expect(response.headers["content-type"]).toMatch(/json/);
77+
expect(response.status).toBe(200);
78+
expect(response.body.res).toMatch(/tutorial updated/);
79+
});
80+
});
81+
});

0 commit comments

Comments
 (0)