Skip to content

Commit

Permalink
🧪 fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultleouay committed Nov 26, 2023
1 parent 74a234d commit 3a5054e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
**/README.md
**/.next
**/.git
node_modules
node_modules
openstatus.db
4 changes: 2 additions & 2 deletions apps/server/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ primary_region = "ams"
internal_port = 3000
force_https = true
auto_stop_machines = false
auto_start_machines = true
min_machines_running = 2
auto_start_machines = false
min_machines_running = 12
processes = ["app"]
[http_service.concurrency]
type = "requests"
Expand Down
40 changes: 18 additions & 22 deletions apps/server/src/checker/checker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ mock.module("./ping.ts", () => {
test("should call upsertMonitorStatus when we can fetch", async () => {
const fn = mock(() => {});

mock.module("./alerting.ts", () => {
mock.module("./monitor-handler.ts", () => {
return {
upsertMonitorStatus: fn,
handleMonitorFailed: mock(() => {}),
handleMonitorRecovered: fn,
};
});

await checkerRetryPolicy({
workspaceId: "1",
monitorId: "1",
Expand All @@ -31,9 +33,10 @@ test("should call upsertMonitorStatus when we can fetch", async () => {
test("should call upsertMonitorStatus when status error", async () => {
const fn = mock(() => {});

mock.module("./alerting.ts", () => {
mock.module("./monitor-handler.ts", () => {
return {
upsertMonitorStatus: fn,
handleMonitorFailed: fn,
handleMonitorRecovered: mock(() => {}),
};
});
try {
Expand All @@ -55,9 +58,9 @@ test("should call upsertMonitorStatus when status error", async () => {
test("What should we do when redirect ", async () => {
const fn = mock(() => {});

mock.module("./alerting.ts", () => {
mock.module("./monitor-handler.ts", () => {
return {
upsertMonitorStatus: fn,
handleMonitorFailed: fn,
};
});
try {
Expand All @@ -79,17 +82,15 @@ test("What should we do when redirect ", async () => {
test("When 404 we should trigger alerting ", async () => {
const fn = mock(() => {});
const fn1 = mock(() => {});
const fn2 = mock(() => {});

mock.module("./alerting.ts", () => {
mock.module("./ping.ts", () => {
return {
upsertMonitorStatus: fn,
triggerAlerting: fn1,
publishPing: fn,
};
});
mock.module("./ping.ts", () => {
mock.module("./monitor-handler.ts", () => {
return {
publishPing: fn2,
handleMonitorFailed: fn1,
};
});
try {
Expand All @@ -107,24 +108,20 @@ test("When 404 we should trigger alerting ", async () => {
}
expect(fn).toHaveBeenCalledTimes(1);
expect(fn1).toHaveBeenCalledTimes(1);
expect(fn2).toHaveBeenCalledTimes(1);
});

test("When error 404 we should not trigger alerting ", async () => {
const fn = mock(() => {});
const fn1 = mock(() => {});
const fn2 = mock(() => {});

mock.module("./alerting.ts", () => {
mock.module("./ping.ts", () => {
return {
upsertMonitorStatus: fn,
triggerAlerting: fn1,
publishPing: fn,
};
});

mock.module("./ping.ts", () => {
mock.module("./monitor-handler.ts", () => {
return {
publishPing: fn2,
handleMonitorFailed: fn1,
};
});
try {
Expand All @@ -140,7 +137,6 @@ test("When error 404 we should not trigger alerting ", async () => {
} catch (e) {
expect(e).toBeInstanceOf(Error);
}
expect(fn).toHaveBeenCalledTimes(0);
expect(fn).toHaveBeenCalledTimes(1);
expect(fn1).toHaveBeenCalledTimes(0);
expect(fn2).toHaveBeenCalledTimes(1);
});
6 changes: 3 additions & 3 deletions apps/server/src/checker/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const run = async (data: Payload, retry: number) => {
message: undefined,
});
if (data?.status === "error") {
handleMonitorRecovered(data, res);
await handleMonitorRecovered(data, res);
}
} else {
if (retry < 2) {
Expand All @@ -94,8 +94,8 @@ const run = async (data: Payload, retry: number) => {
statusCode: res?.status,
message,
});
if (data?.status === "active") {
handleMonitorFailed(data, res, message);
if (data.status === "active") {
await handleMonitorFailed(data, res, message);
}
}
}
Expand Down

0 comments on commit 3a5054e

Please sign in to comment.