test(core-realtime): unit cover registerChannel + listChannels
- 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) <noreply@anthropic.com>
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user