Merge pull request #1192 from bluewave-labs/fix/be/status-service-status-string

Add better status string generation
This commit is contained in:
Alexander Holliday
2024-11-24 18:36:01 -08:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

@@ -11,6 +11,11 @@ class 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.
*
@@ -35,7 +40,7 @@ class StatusService {
this.logger.info({
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,
newStatus: status,
});

View File

@@ -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 () => {
beforeEach(() => {
// statusService.insertCheck = sinon.stub().resolves;