Skip to content

Commit bf84d17

Browse files
Merge branch 'development' into 321-crud-endpoints-testcases-apidoc-for-notification
2 parents 4937987 + d8abd45 commit bf84d17

File tree

4 files changed

+118
-2
lines changed

4 files changed

+118
-2
lines changed

_apidoc.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,3 +1819,59 @@
18191819
* @apiSuccess {String} faculty.natureOfAssociation Nature of association with the institution.
18201820
* @apiSuccess {String} faculty.additionalResponsibilities Additional responsibilities of the faculty.
18211821
*/
1822+
1823+
//------------------------------------------------------------------------------------------
1824+
// Topics.
1825+
// ------------------------------------------------------------------------------------------
1826+
1827+
/**
1828+
* @api {post} /topic/add Add Topic
1829+
* @apiName AddTopic
1830+
* @apiGroup Topic
1831+
*
1832+
* @apiBody {String} title The title of topic.
1833+
*
1834+
* @apiSuccess {String} res Success message with the ID of the added topic.
1835+
*
1836+
* @apiError (Error 500) DatabaseError Error while inserting in the database.
1837+
*
1838+
* @apiDescription Adds a new topic to the system.
1839+
*/
1840+
1841+
/**
1842+
* @api {get} topic/list Get Topic List
1843+
* @apiName GetTopic
1844+
* @apiGroup Topic
1845+
*
1846+
* @apiQuery {String} [title] Title of Topic.
1847+
*
1848+
* @apiSuccess {String} topic.title Title of Topic.
1849+
*/
1850+
1851+
/**
1852+
* @api {delete} /topic/delete/:topicId Delete Topic
1853+
* @apiName DeleteTopic,
1854+
* @apiGroup Topic
1855+
*
1856+
* @apiParam {String} topicId The ID of the topic document to delete.
1857+
*
1858+
* @apiSuccess {String} res Success message indicating the deletion.
1859+
*
1860+
* @apiError (Error 500) err Error message if there was an error during the deletion.
1861+
*
1862+
* */
1863+
/**
1864+
* @api {post} /topic/update/:id Update topic details
1865+
* @apiName UpdateTopic
1866+
* @apiGroup Topic
1867+
* @apiDescription update Existing Topic details
1868+
*
1869+
* @apiParam {String} id The topic document to update.
1870+
* @apiBody {String} id Id of the topic to be updated
1871+
* @apiBody {String} [title] The title of topic.
1872+
1873+
*
1874+
* @apiSuccess {String} res topic updated.
1875+
* @apiError (Error 500) err Error in updating database
1876+
*
1877+
*/

app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ app.use("/semester", semesterRouter);
7171
app.use("/faculty", facultyRouter);
7272
app.use("/performance", performarouter);
7373
app.use("/notification", notificationRouter);
74-
app.use("topic",topicRouter);
74+
app.use("/topic",topicRouter);
75+
7576
export default app;

controller/topic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
try {
1111
// eslint-disable-next-line max-len
1212
const topic = await addNewTopic(title);
13-
res.json({ res: `added accreditation ${topic.name}`, id: topic.id });
13+
res.json({ res: `added topic ${topic.name}`, id: topic.id });
1414
} catch (error) {
1515
logger.error("Error while inserting", error);
1616
res.status(500);

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)