Co-authored-by: justsomelegs <[email protected]> Co-authored-by: codex <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { scopeThreadRef } from "@t3tools/client-runtime";
|
|
import { ThreadId } from "@t3tools/contracts";
|
|
import { DraftId } from "./composerDraftStore";
|
|
|
|
import {
|
|
buildDraftThreadRouteParams,
|
|
buildThreadRouteParams,
|
|
resolveThreadRouteRef,
|
|
resolveThreadRouteTarget,
|
|
} from "./threadRoutes";
|
|
|
|
describe("threadRoutes", () => {
|
|
it("builds canonical thread route params from a scoped ref", () => {
|
|
const ref = scopeThreadRef("env-1" as never, ThreadId.makeUnsafe("thread-1"));
|
|
|
|
expect(buildThreadRouteParams(ref)).toEqual({
|
|
environmentId: "env-1",
|
|
threadId: "thread-1",
|
|
});
|
|
});
|
|
|
|
it("resolves a scoped ref only when both params are present", () => {
|
|
expect(
|
|
resolveThreadRouteRef({
|
|
environmentId: "env-1",
|
|
threadId: "thread-1",
|
|
}),
|
|
).toEqual({
|
|
environmentId: "env-1",
|
|
threadId: "thread-1",
|
|
});
|
|
|
|
expect(resolveThreadRouteRef({ environmentId: "env-1" })).toBeNull();
|
|
expect(resolveThreadRouteRef({ threadId: "thread-1" })).toBeNull();
|
|
});
|
|
|
|
it("builds canonical draft route params from a draft id", () => {
|
|
expect(buildDraftThreadRouteParams(DraftId.makeUnsafe("draft-1"))).toEqual({
|
|
draftId: "draft-1",
|
|
});
|
|
});
|
|
|
|
it("resolves draft and server route targets", () => {
|
|
expect(
|
|
resolveThreadRouteTarget({
|
|
environmentId: "env-1",
|
|
threadId: "thread-1",
|
|
}),
|
|
).toEqual({
|
|
kind: "server",
|
|
threadRef: {
|
|
environmentId: "env-1",
|
|
threadId: "thread-1",
|
|
},
|
|
});
|
|
|
|
expect(
|
|
resolveThreadRouteTarget({
|
|
draftId: "draft-1",
|
|
}),
|
|
).toEqual({
|
|
kind: "draft",
|
|
draftId: "draft-1",
|
|
});
|
|
});
|
|
});
|