Update test case to check for the specific errors and remove test case for empty URL
This commit is contained in:
1 parent
5d3e1796e0
commit
7f0d5d4255
1 file changed
+4
-10
@@ -482,27 +482,21 @@ describe("Monitor Controllor - checkEndpointResolution", () => {
|
|||||||
});
|
});
|
||||||
it("should return a 400 error message if DNS resolution fails", async () => {
|
it("should return a 400 error message if DNS resolution fails", async () => {
|
||||||
const dnsError = new Error("DNS resolution failed");
|
const dnsError = new Error("DNS resolution failed");
|
||||||
|
dnsError.code = 'ENOTFOUND';
|
||||||
dnsResolveStub.callsFake((hostname, callback) => callback(dnsError));
|
dnsResolveStub.callsFake((hostname, callback) => callback(dnsError));
|
||||||
await checkEndpointResolution(req, res, next);
|
await checkEndpointResolution(req, res, next);
|
||||||
expect(next.calledOnce).to.be.true;
|
expect(next.calledOnce).to.be.true;
|
||||||
const errorPassedToNext = next.getCall(0).args[0];
|
const errorPassedToNext = next.getCall(0).args[0];
|
||||||
expect(errorPassedToNext).to.be.an.instanceOf(Error);
|
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 () => {
|
it('should call next with an error for invalid monitorURL', async () => {
|
||||||
req.query.monitorURL = 'invalid-url';
|
req.query.monitorURL = 'invalid-url';
|
||||||
await checkEndpointResolution(req, res, next);
|
await checkEndpointResolution(req, res, next);
|
||||||
expect(next.calledOnce).to.be.true;
|
expect(next.calledOnce).to.be.true;
|
||||||
const error = next.getCall(0).args[0];
|
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');
|
|
||||||
});
|
|
||||||
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.message).to.include('Invalid URL');
|
expect(error.message).to.include('Invalid URL');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user