From cbac166782cd6d3f20f3f035219cbb7f893f9ad1 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Sat, 9 May 2026 00:42:35 +0200 Subject: [PATCH] test(core-realtime): unit cover registerChannel + listChannels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add 4 new test cases to RealtimeHandlerRegistry test suite - registerChannel stores outbound-only descriptors distinct from inbound - listChannels() includes both inbound (from register) and outbound-only channels - Validates backward-compat guarantee and re-registration behavior Test count: 4 → 8 in realtime-handler-registry.test.ts All 35 tests in core-realtime pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../src/realtime-handler-registry.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/packages/core-realtime/src/realtime-handler-registry.test.ts b/packages/core-realtime/src/realtime-handler-registry.test.ts index c40ebea..cf6c7a8 100644 --- a/packages/core-realtime/src/realtime-handler-registry.test.ts +++ b/packages/core-realtime/src/realtime-handler-registry.test.ts @@ -41,4 +41,51 @@ describe("RealtimeHandlerRegistry", () => { expect(reg.getInboundDescriptor("test.ch")!.handler).toBe(h2); expect(reg.list()).toHaveLength(1); }); + + it("registerChannel stores a descriptor that appears in listChannels() but not in list()", () => { + const reg = new RealtimeHandlerRegistry(); + const outboundCh = defineRealtimeChannel( + "test.outbound", + z.object({ y: z.string() }).strict(), + { scope: "authenticated" }, + ); + reg.registerChannel(outboundCh); + expect(reg.listChannels()).toHaveLength(1); + expect(reg.listChannels()[0]!.name).toBe("test.outbound"); + expect(reg.list()).toHaveLength(0); + }); + + it("register auto-populates listChannels()", () => { + const reg = new RealtimeHandlerRegistry(); + reg.register({ descriptor: ch, handler: vi.fn() }); + expect(reg.listChannels()).toHaveLength(1); + expect(reg.listChannels()[0]!.name).toBe("test.ch"); + }); + + it("listChannels() returns both inbound and outbound-only channels when both are registered", () => { + const reg = new RealtimeHandlerRegistry(); + const outboundCh = defineRealtimeChannel( + "test.outbound", + z.object({ y: z.string() }).strict(), + { scope: "authenticated" }, + ); + reg.register({ descriptor: ch, handler: vi.fn() }); + reg.registerChannel(outboundCh); + expect(reg.listChannels()).toHaveLength(2); + const names = reg.listChannels().map((c) => c.name).sort(); + expect(names).toEqual(["test.ch", "test.outbound"]); + }); + + it("re-registering an outbound-only channel via registerChannel replaces the previous entry", () => { + const reg = new RealtimeHandlerRegistry(); + const outboundCh = defineRealtimeChannel( + "test.outbound", + z.object({ y: z.string() }).strict(), + { scope: "authenticated" }, + ); + reg.registerChannel(outboundCh); + reg.registerChannel(outboundCh); + expect(reg.listChannels()).toHaveLength(1); + expect(reg.listChannels()[0]!.name).toBe("test.outbound"); + }); });