-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from tcet-opensource/254-topics.endpoints
added api-testcase
- Loading branch information
Showing
5 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { jest } from "@jest/globals"; // eslint-disable-line import/no-extraneous-dependencies | ||
import topicModel from "#models/topic"; | ||
import connector from "#models/databaseUtil"; | ||
|
||
jest.mock("#util"); | ||
|
||
const { agent } = global; | ||
|
||
function cleanUp(callback) { | ||
topicModel.remove({ title: "xyz" }).then(() => { | ||
connector.disconnect((DBerr) => { | ||
if (DBerr) console.log("Database dissconnnect error: ", DBerr); | ||
}); | ||
callback(); | ||
}); | ||
} | ||
|
||
afterAll((done) => { | ||
cleanUp(done); | ||
}); | ||
|
||
describe("checking topic functions", () => { | ||
it("create topic", async () => { | ||
const response = await agent.post("/topic/add").send({ | ||
title: "xyz", | ||
}); | ||
expect(response.headers["content-type"]).toMatch(/json/); | ||
expect(response.status).toBe(200); | ||
expect(response.body.res).toMatch(/added topic/); | ||
}); | ||
let id; | ||
beforeEach(async () => { | ||
id = await agent.post("/topic/add").send({ | ||
title: "xyz", | ||
}); | ||
id = JSON.parse(id.res.text).id; | ||
}); | ||
|
||
afterEach(async () => { | ||
await topicModel.remove({ title: "xyz" }); | ||
}); | ||
|
||
it("read topic", async () => { | ||
const response = await agent | ||
.get("/topic/list") | ||
.send({ title: "xyz" }); | ||
expect(response.status).toBe(200); | ||
expect(response.body.res).toBeDefined(); | ||
}); | ||
|
||
it("update topic", async () => { | ||
const response = await agent | ||
.post(`/topic/update/${id}`) | ||
.send({ title: "xyz" }, { title: "123" }); | ||
expect(response.headers["content-type"]).toMatch(/json/); | ||
expect(response.status).toBe(200); | ||
expect(response.body.res).toMatch(/topic updated/); | ||
}); | ||
}); |