fixed error in handlePing test

This commit is contained in:
Alex Holliday committed 2024-10-23 11:25:33 +08:00
1 parent 2fcdb20883
commit 1c2d758e17
1 file changed
+8 -15
+8 -15
View File
@@ -308,43 +308,36 @@ describe("networkService - handlePing", () => {
sinon.restore(); sinon.restore();
}); });
it("should handle a successful ping response", async function () { it("should handle a successful ping response", async () => {
const response = { alive: true }; const response = { alive: true };
const responseTime = 0; const responseTime = 0;
pingMock.promise.probe.resolves(response); pingMock.promise.probe.returns(response);
logAndStoreCheckStub.resolves(); logAndStoreCheckStub.resolves();
await networkService.handlePing(job); await networkService.handlePing(job);
expect( expect(
logAndStoreCheckStub.calledOnceWith( logAndStoreCheckStub.calledOnceWith({
{
monitorId: job.data._id, monitorId: job.data._id,
status: true, status: response.alive,
responseTime, responseTime,
message: successMessages.PING_SUCCESS, message: successMessages.PING_SUCCESS,
}, })
networkService.db.createCheck
)
).to.be.true; ).to.be.true;
expect(handleStatusUpdateStub.calledOnceWith(job, true)).to.be.true; expect(handleStatusUpdateStub.calledOnceWith(job, true)).to.be.true;
}); });
it("should handle a successful ping response and isAlive === false", async function () { it("should handle a successful response and isAlive === false", async function () {
const response = { alive: false }; const response = { alive: false };
const responseTime = 0; const responseTime = 0;
pingMock.promise.probe.resolves(response); pingMock.promise.probe.resolves(response);
logAndStoreCheckStub.resolves(); logAndStoreCheckStub.resolves();
await networkService.handlePing(job); await networkService.handlePing(job);
console.log(logAndStoreCheckStub.getCall(0).args[0]);
expect( expect(
logAndStoreCheckStub.calledOnceWith( logAndStoreCheckStub.calledOnceWith({
{
monitorId: job.data._id, monitorId: job.data._id,
status: false, status: false,
responseTime, responseTime,
message: errorMessages.PING_CANNOT_RESOLVE, message: errorMessages.PING_CANNOT_RESOLVE,
}, })
networkService.db.createCheck
)
).to.be.true; ).to.be.true;
expect(handleStatusUpdateStub.calledOnceWith(job, false)).to.be.true; expect(handleStatusUpdateStub.calledOnceWith(job, false)).to.be.true;
}); });