26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { z } from "zod";
|
|
import { defineRealtimeChannel } from "@/realtime-channel";
|
|
|
|
describe("defineRealtimeChannel", () => {
|
|
it("returns a descriptor with name, schema, and scope", () => {
|
|
const ch = defineRealtimeChannel(
|
|
"test.channel",
|
|
z.object({ id: z.string() }).strict(),
|
|
{ scope: "public" },
|
|
);
|
|
expect(ch.name).toBe("test.channel");
|
|
expect(ch.scope).toBe("public");
|
|
expect(() => ch.schema.parse({ id: "x" })).not.toThrow();
|
|
});
|
|
|
|
it("preserves all four scope shapes", () => {
|
|
expect(defineRealtimeChannel("a", z.object({}), { scope: "public" }).scope).toBe("public");
|
|
expect(defineRealtimeChannel("a", z.object({}), { scope: "authenticated" }).scope).toBe("authenticated");
|
|
expect(defineRealtimeChannel("a", z.object({}), { scope: { role: "admin" } }).scope).toEqual({ role: "admin" });
|
|
expect(
|
|
defineRealtimeChannel("a", z.object({}), { scope: { userScoped: true, template: "x.{id}" } }).scope,
|
|
).toEqual({ userScoped: true, template: "x.{id}" });
|
|
});
|
|
});
|