feat(core-realtime): channel-template matcher (placeholder extraction)

This commit is contained in:
2026-05-08 21:13:18 +02:00
parent 691b4942d5
commit 0771601571
2 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import { describe, it, expect } from "vitest";
import { matchChannelTemplate } from "@/channel-template";
describe("matchChannelTemplate", () => {
it("matches a plain channel name exactly", () => {
expect(matchChannelTemplate("blog.feed", "blog.feed")).toEqual({ params: {} });
expect(matchChannelTemplate("blog.feed", "blog.other")).toBeNull();
});
it("matches a templated channel and extracts params", () => {
expect(
matchChannelTemplate("notifications.user.{userId}", "notifications.user.user_42"),
).toEqual({ params: { userId: "user_42" } });
});
it("returns null when a templated channel doesn't match the shape", () => {
expect(
matchChannelTemplate("notifications.user.{userId}", "notifications.user"),
).toBeNull();
expect(
matchChannelTemplate("notifications.user.{userId}", "blog.feed"),
).toBeNull();
});
it("supports multiple placeholders", () => {
expect(
matchChannelTemplate(
"rooms.{roomId}.user.{userId}",
"rooms.r1.user.u1",
),
).toEqual({ params: { roomId: "r1", userId: "u1" } });
});
});