mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-07 00:44:49 +00:00
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
buildNotificationRoute,
|
|
resolveNotificationTarget,
|
|
} from "./notification-routing";
|
|
|
|
describe("resolveNotificationTarget", () => {
|
|
it("extracts non-empty server and agent ids", () => {
|
|
expect(
|
|
resolveNotificationTarget({
|
|
serverId: " server-123 ",
|
|
agentId: " agent-456 ",
|
|
})
|
|
).toEqual({
|
|
serverId: "server-123",
|
|
agentId: "agent-456",
|
|
});
|
|
});
|
|
|
|
it("returns null for missing/empty ids", () => {
|
|
expect(resolveNotificationTarget({ serverId: "", agentId: " " })).toEqual({
|
|
serverId: null,
|
|
agentId: null,
|
|
});
|
|
expect(resolveNotificationTarget(undefined)).toEqual({
|
|
serverId: null,
|
|
agentId: null,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("buildNotificationRoute", () => {
|
|
it("routes directly to server-scoped agent path when both ids are present", () => {
|
|
expect(buildNotificationRoute({ serverId: "srv-1", agentId: "agent-1" })).toBe(
|
|
"/h/srv-1/agent/agent-1"
|
|
);
|
|
});
|
|
|
|
it("falls back to host-scoped draft route when only serverId is present", () => {
|
|
expect(buildNotificationRoute({ serverId: "srv-only" })).toBe("/h/srv-only/agent");
|
|
});
|
|
|
|
it("falls back to root when no server id is present", () => {
|
|
expect(buildNotificationRoute({ agentId: "agent-legacy" })).toBe("/");
|
|
expect(buildNotificationRoute(undefined)).toBe("/");
|
|
});
|
|
|
|
it("encodes path segments", () => {
|
|
expect(
|
|
buildNotificationRoute({
|
|
serverId: "srv/with/slash",
|
|
agentId: "agent with space",
|
|
})
|
|
).toBe("/h/srv%2Fwith%2Fslash/agent/agent%20with%20space");
|
|
});
|
|
});
|