From 95714482e228f630da22c8ea95a9a810fe7792d3 Mon Sep 17 00:00:00 2001 From: david <58231312+davseby@users.noreply.github.com> Date: Sat, 5 Sep 2026 22:40:41 +0300 Subject: [PATCH] add more unit tests to auth-realtime --- server/auth-realtime/src/routes.test.ts | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/server/auth-realtime/src/routes.test.ts b/server/auth-realtime/src/routes.test.ts index c7a7d661..30e95acb 100644 --- a/server/auth-realtime/src/routes.test.ts +++ b/server/auth-realtime/src/routes.test.ts @@ -562,6 +562,27 @@ describe("createRoutes", () => { expect(core.updateBranch).toHaveBeenCalledTimes(0) expect(resetConnections).toHaveBeenCalledTimes(0) }) + + it("keeps the connections when core is unreachable", async ({ + expect, + }) => { + const core = stubCore() + core.updateBranch.mockRejectedValue( + new Error("connect ECONNREFUSED"), + ) + const { app, resetConnections } = build({ core }) + + const res = await app.request( + "/documents/doc1/branches/b1", + json({ protected: true }), + ) + + expect(res.status).toBe(500) + expect(await res.json()).toEqual({ + error: "failed to update branch", + }) + expect(resetConnections).toHaveBeenCalledTimes(0) + }) }) describe("DELETE /documents/:documentId/branches/:branchId", () => { @@ -626,6 +647,27 @@ describe("createRoutes", () => { }) expect(resetConnections).toHaveBeenCalledTimes(0) }) + + it("keeps the connections when core is unreachable", async ({ + expect, + }) => { + const core = stubCore() + core.deleteBranch.mockRejectedValue( + new Error("connect ECONNREFUSED"), + ) + const { app, resetConnections } = build({ core }) + + const res = await app.request( + "/documents/doc1/branches/b1", + { method: "DELETE" }, + ) + + expect(res.status).toBe(500) + expect(await res.json()).toEqual({ + error: "failed to delete branch", + }) + expect(resetConnections).toHaveBeenCalledTimes(0) + }) }) describe("PUT /documents/:documentId/merge", () => {