diff --git a/src/commands/health.test.ts b/src/commands/health.test.ts index 572a2097f..89e99bf87 100644 --- a/src/commands/health.test.ts +++ b/src/commands/health.test.ts @@ -26,7 +26,7 @@ vi.mock("../web/session.js", () => ({ createWaSocket: vi.fn(async () => ({ ws: { close: vi.fn() }, ev: { on: vi.fn() } })), waitForWaConnection: (...args: unknown[]) => waitForWaConnection(...args), webAuthExists: (...args: unknown[]) => webAuthExists(...args), - getStatusCode: () => undefined, + getStatusCode: vi.fn(() => 440), getWebAuthAgeMs: () => 5000, logWebSelfId: vi.fn(), })); @@ -59,4 +59,17 @@ describe("healthCommand", () => { await healthCommand({ json: true }, runtime as never); expect(runtime.exit).toHaveBeenCalledWith(1); }); + + it("exits non-zero when connect fails", async () => { + webAuthExists.mockResolvedValue(true); + waitForWaConnection.mockRejectedValueOnce({ output: { statusCode: 440 } }); + + await healthCommand({ json: true }, runtime as never); + + expect(runtime.exit).toHaveBeenCalledWith(1); + const logged = runtime.log.mock.calls[0][0] as string; + const parsed = JSON.parse(logged); + expect(parsed.web.connect.ok).toBe(false); + expect(parsed.web.connect.status).toBe(440); + }); });