Add missing tests for 100% coverage
This commit is contained in:
1 parent
ab4cf69222
commit
150b4c6f0f
3 files changed
+23
-4
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
require: ["chai/register-expect.js"], // Include Chai's "expect" interface globally
|
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
|
timeout: 5000, // Set test-case timeout in milliseconds
|
||||||
recursive: true, // Include subdirectories
|
recursive: true, // Include subdirectories
|
||||||
reporter: "spec", // Use the "spec" reporter
|
reporter: "spec", // Use the "spec" reporter
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const createCheck = async (req, res, next) => {
|
|||||||
.status(200)
|
.status(200)
|
||||||
.json({ success: true, msg: successMessages.CHECK_CREATE, data: check });
|
.json({ success: true, msg: successMessages.CHECK_CREATE, data: check });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
next(handleError(error, SERVICE_NAME, "createCheck"));
|
next(handleError(error, SERVICE_NAME, "createCheck"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,7 +43,25 @@ describe("Check Controller - createCheck", () => {
|
|||||||
};
|
};
|
||||||
await createCheck(req, res, next);
|
await createCheck(req, res, next);
|
||||||
expect(next.firstCall.args[0]).to.be.an("error");
|
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 () => {
|
it("should return a success message if check is created", async () => {
|
||||||
req.params = {
|
req.params = {
|
||||||
monitorId: "monitorId",
|
monitorId: "monitorId",
|
||||||
@@ -115,12 +133,12 @@ describe("Check Controller - getChecks", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should call next with error if data retrieval fails", async () => {
|
it("should call next with error if data retrieval fails", async () => {
|
||||||
|
req.params = {
|
||||||
|
monitorId: "monitorId",
|
||||||
|
};
|
||||||
req.db.getChecks.rejects(new Error("error"));
|
req.db.getChecks.rejects(new Error("error"));
|
||||||
await getChecks(req, res, next);
|
await getChecks(req, res, next);
|
||||||
expect(next.firstCall.args[0]).to.be.an("error");
|
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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user