From 7f0d5d42551a8c63ec01f21d79a32875083eb21c Mon Sep 17 00:00:00 2001 From: om-3004 Date: Thu, 17 Oct 2024 11:16:49 +0530 Subject: [PATCH] Update test case to check for the specific errors and remove test case for empty URL --- Server/tests/controllers/monitorController.test.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Server/tests/controllers/monitorController.test.js b/Server/tests/controllers/monitorController.test.js index 26c6a6048..690649660 100644 --- a/Server/tests/controllers/monitorController.test.js +++ b/Server/tests/controllers/monitorController.test.js @@ -482,27 +482,21 @@ describe("Monitor Controllor - checkEndpointResolution", () => { }); it("should return a 400 error message if DNS resolution fails", async () => { const dnsError = new Error("DNS resolution failed"); + dnsError.code = 'ENOTFOUND'; dnsResolveStub.callsFake((hostname, callback) => callback(dnsError)); await checkEndpointResolution(req, res, next); expect(next.calledOnce).to.be.true; const errorPassedToNext = next.getCall(0).args[0]; expect(errorPassedToNext).to.be.an.instanceOf(Error); - expect(errorPassedToNext.message).to.include('DNS resolution failed'); + expect(errorPassedToNext.message).to.include('DNS resolution failed'); + expect(errorPassedToNext.code).to.equal('ENOTFOUND'); }); it('should call next with an error for invalid monitorURL', async () => { req.query.monitorURL = 'invalid-url'; await checkEndpointResolution(req, res, next); expect(next.calledOnce).to.be.true; const error = next.getCall(0).args[0]; - expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.include('Invalid URL'); - }); - it('should handle an edge case where monitorURL is not provided', async () => { - req.query = {}; - await checkEndpointResolution(req, res, next); - expect(next.calledOnce).to.be.true; - const error = next.getCall(0).args[0]; - expect(error).to.be.an.instanceOf(Error); + expect(error).to.be.an.instanceOf(TypeError); expect(error.message).to.include('Invalid URL'); }); });