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"); + }); });