Add missing tests for 100% coverage

This commit is contained in:
Alex Holliday
2024-10-11 11:40:10 +08:00
parent ab4cf69222
commit 150b4c6f0f
3 changed files with 23 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
module.exports = {
require: ["chai/register-expect.js"], // Include Chai's "expect" interface globally
// spec: "tests/**/*.test.js", // Specify test files
spec: "tests/**/*.test.js", // Specify test files
timeout: 5000, // Set test-case timeout in milliseconds
recursive: true, // Include subdirectories
reporter: "spec", // Use the "spec" reporter
+1
View File
@@ -31,6 +31,7 @@ const createCheck = async (req, res, next) => {
.status(200)
.json({ success: true, msg: successMessages.CHECK_CREATE, data: check });
} catch (error) {
console.log(error);
next(handleError(error, SERVICE_NAME, "createCheck"));
}
};
@@ -43,7 +43,25 @@ describe("Check Controller - createCheck", () => {
};
await createCheck(req, res, next);
expect(next.firstCall.args[0]).to.be.an("error");
expect(next.firstCall.args[0].status).to.equal(422);
});
it("should call next with error if data retrieval fails", async () => {
req.params = {
monitorId: "monitorId",
};
req.body = {
monitorId: "monitorId",
status: true,
responseTime: 100,
statusCode: 200,
message: "message",
};
req.db.createCheck.rejects(new Error("error"));
await createCheck(req, res, next);
expect(next.firstCall.args[0]).to.be.an("error");
});
it("should return a success message if check is created", async () => {
req.params = {
monitorId: "monitorId",
@@ -115,12 +133,12 @@ describe("Check Controller - getChecks", () => {
});
it("should call next with error if data retrieval fails", async () => {
req.params = {
monitorId: "monitorId",
};
req.db.getChecks.rejects(new Error("error"));
await getChecks(req, res, next);
expect(next.firstCall.args[0]).to.be.an("error");
req.db.getChecks.resolves([]);
req.db.getChecksCount.rejects(new Error("error"));
await getChecks(req, res, next);
});
});