Merge pull request #1192 from bluewave-labs/fix/be/status-service-status-string
Add better status string generation
This commit is contained in:
2 files changed
+18
-1
No files matched your search
@@ -11,6 +11,11 @@ class StatusService {
|
|||||||
this.SERVICE_NAME = "StatusService";
|
this.SERVICE_NAME = "StatusService";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getStatusString = (status) => {
|
||||||
|
if (status === true) return "up";
|
||||||
|
if (status === false) return "down";
|
||||||
|
return "unknown";
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Updates the status of a monitor based on the network response.
|
* Updates the status of a monitor based on the network response.
|
||||||
*
|
*
|
||||||
@@ -35,7 +40,7 @@ class StatusService {
|
|||||||
|
|
||||||
this.logger.info({
|
this.logger.info({
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
message: `${monitor.name} went from ${monitor.status === true ? "up" : "down"} to ${status === true ? "up" : "down"}`,
|
message: `${monitor.name} went from ${this.getStatusString(monitor.status)} to ${this.getStatusString(status)}`,
|
||||||
prevStatus: monitor.status,
|
prevStatus: monitor.status,
|
||||||
newStatus: status,
|
newStatus: status,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,6 +27,18 @@ describe("StatusService", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("getStatusString", () => {
|
||||||
|
it("should return 'up' if status is true", () => {
|
||||||
|
expect(statusService.getStatusString(true)).to.equal("up");
|
||||||
|
});
|
||||||
|
it("should return 'down' if status is false", () => {
|
||||||
|
expect(statusService.getStatusString(false)).to.equal("down");
|
||||||
|
});
|
||||||
|
it("should return 'unknown' if status is undefined or null", () => {
|
||||||
|
expect(statusService.getStatusString(undefined)).to.equal("unknown");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("updateStatus", async () => {
|
describe("updateStatus", async () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// statusService.insertCheck = sinon.stub().resolves;
|
// statusService.insertCheck = sinon.stub().resolves;
|
||||||
|
|||||||
Reference in new issue
Block a user