Skip to content

Commit

Permalink
Added testcases for accreditation endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruvrg committed Aug 20, 2023
1 parent b220726 commit bcc29fa
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devstart": "nodemon ./bin/www",
"serverstart": "DEBUG=api:* npm run devstart",
"serverstartWin": "SET DEBUG=api:* && npm run devstart",
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
"test": "SET NODE_OPTIONS=--experimental-vm-modules && npx jest",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules npx jest --watch",
"test:openHandels": "NODE_OPTIONS=--experimental-vm-modules npx jest --detectOpenHandles",
"eslint": "eslint ."
Expand Down
76 changes: 76 additions & 0 deletions test/routes/accreditation.test.js
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/);
});
});

0 comments on commit bcc29fa

Please sign in to comment.