-
-
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.
Added testcases for accreditation endpoints
- Loading branch information
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,76 @@ | ||
import request from "supertest"; | ||
import { jest } from "@jest/globals"; // eslint-disable-line import/no-extraneous-dependencies | ||
import app from "#app"; | ||
import accreditationModel from "#models/accreditation"; | ||
import connector from "#models/databaseUtil"; | ||
|
||
jest.mock("#util"); | ||
|
||
let server; | ||
let agent; | ||
beforeAll((done) => { | ||
server = app.listen(5000, () => { | ||
agent = request.agent(server); | ||
connector.set("debug", false); | ||
done(); | ||
}); | ||
}); | ||
|
||
function cleanUp(callback) { | ||
accreditationModel.remove({ name: "xyz" }).then(() => { | ||
connector.disconnect((DBerr) => { | ||
if (DBerr) console.log("Database dissconnnect error: ", DBerr); | ||
server.close((serverErr) => { | ||
if (serverErr) console.log(serverErr); | ||
callback(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
afterAll((done) => { | ||
cleanUp(done); | ||
}); | ||
|
||
describe("checking accreditation functions", () => { | ||
it("create accreditation", async () => { | ||
const response = await agent.post("/accreditation/add").send({ | ||
name: "xyz", | ||
agencyName: "abc", | ||
dateofAccreditation: "2023-06-18T14:11:30Z", | ||
dateofExpiry: "2023-05-28T14:10:30Z", | ||
}); | ||
expect(response.headers["content-type"]).toMatch(/json/); | ||
expect(response.status).toBe(200); | ||
expect(response.body.res).toMatch(/added accreditation/); | ||
}); | ||
|
||
beforeEach(async () => { | ||
agent.post("/accreditation/add").send({ | ||
name: "xyz", | ||
agencyName: "abc", | ||
dateofAccreditation: "2023-06-18T14:11:30Z", | ||
dateofExpiry: "2023-05-28T14:10:30Z", | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
await accreditationModel.remove({ name: "xyz" }); | ||
}); | ||
|
||
it("read accreditation", async () => { | ||
const response = await agent | ||
.post("/accreditation/list") | ||
.send({ name: "xyz" }); | ||
expect(response.body.res).not.toBeNull(); | ||
}); | ||
|
||
it("update accreditation", async () => { | ||
const response = await agent | ||
.post("/accreditation/update") | ||
.send({ name: "xyz" }, { name: "123" }); | ||
expect(response.headers["content-type"]).toMatch(/json/); | ||
expect(response.status).toBe(200); | ||
expect(response.body.res).toMatch(/accreditation updated/); | ||
}); | ||
}); |