Skip to content

Commit 4cae035

Browse files
committed
added api-testcase
1 parent 81d808e commit 4cae035

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

_apidoc.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,3 +1594,59 @@
15941594
* @apiSuccess {String} faculty.natureOfAssociation Nature of association with the institution.
15951595
* @apiSuccess {String} faculty.additionalResponsibilities Additional responsibilities of the faculty.
15961596
**/
1597+
1598+
//------------------------------------------------------------------------------------------
1599+
// Topics.
1600+
// ------------------------------------------------------------------------------------------
1601+
1602+
/**
1603+
* @api {post} /topic/add Add Topic
1604+
* @apiName AddTopic
1605+
* @apiGroup Topic
1606+
*
1607+
* @apiBody {String} title The title of topic.
1608+
*
1609+
* @apiSuccess {String} res Success message with the ID of the added topic.
1610+
*
1611+
* @apiError (Error 500) DatabaseError Error while inserting in the database.
1612+
*
1613+
* @apiDescription Adds a new topic to the system.
1614+
*/
1615+
1616+
/**
1617+
* @api {get} topic/list Get Topic List
1618+
* @apiName GetTopic
1619+
* @apiGroup Topic
1620+
*
1621+
* @apiQuery {String} [title] Title of Topic.
1622+
*
1623+
* @apiSuccess {String} topic.title Title of Topic.
1624+
*/
1625+
1626+
/**
1627+
* @api {delete} /topic/delete/:topicId Delete Topic
1628+
* @apiName DeleteTopic,
1629+
* @apiGroup Topic
1630+
*
1631+
* @apiParam {String} topicId The ID of the topic document to delete.
1632+
*
1633+
* @apiSuccess {String} res Success message indicating the deletion.
1634+
*
1635+
* @apiError (Error 500) err Error message if there was an error during the deletion.
1636+
*
1637+
* */
1638+
/**
1639+
* @api {post} /topic/update/:id Update topic details
1640+
* @apiName UpdateTopic
1641+
* @apiGroup Topic
1642+
* @apiDescription update Existing Topic details
1643+
*
1644+
* @apiParam {String} id The topic document to update.
1645+
* @apiBody {String} id Id of the topic to be updated
1646+
* @apiBody {String} [title] The title of topic.
1647+
1648+
*
1649+
* @apiSuccess {String} res topic updated.
1650+
* @apiError (Error 500) err Error in updating database
1651+
*
1652+
*/

test/routes/topic.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { jest } from "@jest/globals"; // eslint-disable-line import/no-extraneous-dependencies
2+
import topicModel from "#models/topic";
3+
import connector from "#models/databaseUtil";
4+
5+
jest.mock("#util");
6+
7+
const { agent } = global;
8+
9+
function cleanUp(callback) {
10+
topicModel.remove({ title: "xyz" }).then(() => {
11+
connector.disconnect((DBerr) => {
12+
if (DBerr) console.log("Database dissconnnect error: ", DBerr);
13+
});
14+
callback();
15+
});
16+
}
17+
18+
afterAll((done) => {
19+
cleanUp(done);
20+
});
21+
22+
describe("checking topic functions", () => {
23+
it("create topic", async () => {
24+
const response = await agent.post("/topic/add").send({
25+
title: "xyz",
26+
});
27+
expect(response.headers["content-type"]).toMatch(/json/);
28+
expect(response.status).toBe(200);
29+
expect(response.body.res).toMatch(/added topic/);
30+
});
31+
let id;
32+
beforeEach(async () => {
33+
id = await agent.post("/topic/add").send({
34+
title: "xyz",
35+
});
36+
id = JSON.parse(id.res.text).id;
37+
});
38+
39+
afterEach(async () => {
40+
await topicModel.remove({ title: "xyz" });
41+
});
42+
43+
it("read topic", async () => {
44+
const response = await agent
45+
.get("/topic/list")
46+
.send({ title: "xyz" });
47+
expect(response.status).toBe(200);
48+
expect(response.body.res).toBeDefined();
49+
});
50+
51+
it("update topic", async () => {
52+
const response = await agent
53+
.post(`/topic/update/${id}`)
54+
.send({ title: "xyz" }, { title: "123" });
55+
expect(response.headers["content-type"]).toMatch(/json/);
56+
expect(response.status).toBe(200);
57+
expect(response.body.res).toMatch(/topic updated/);
58+
});
59+
});

0 commit comments

Comments
 (0)