Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadRoutes.test.ts

67 lines1.7 KB

1import { describe, expect, it } from "vitest";
2import { scopeThreadRef } from "@t3tools/client-runtime";
3import { ThreadId } from "@t3tools/contracts";
4import { DraftId } from "./composerDraftStore";
5​
6import {
7 buildDraftThreadRouteParams,
8 buildThreadRouteParams,
9 resolveThreadRouteRef,
10 resolveThreadRouteTarget,
11} from "./threadRoutes";
12​
13describe("threadRoutes", () => {
14 it("builds canonical thread route params from a scoped ref", () => {
15 const ref = scopeThreadRef("env-1" as never, ThreadId.make("thread-1"));
16​
17 expect(buildThreadRouteParams(ref)).toEqual({
18 environmentId: "env-1",
19 threadId: "thread-1",
20 });
21 });
22​
23 it("resolves a scoped ref only when both params are present", () => {
24 expect(
25 resolveThreadRouteRef({
26 environmentId: "env-1",
27 threadId: "thread-1",
28 }),
29 ).toEqual({
30 environmentId: "env-1",
31 threadId: "thread-1",
32 });
33​
34 expect(resolveThreadRouteRef({ environmentId: "env-1" })).toBeNull();
35 expect(resolveThreadRouteRef({ threadId: "thread-1" })).toBeNull();
36 });
37​
38 it("builds canonical draft route params from a draft id", () => {
39 expect(buildDraftThreadRouteParams(DraftId.make("draft-1"))).toEqual({
40 draftId: "draft-1",
41 });
42 });
43​
44 it("resolves draft and server route targets", () => {
45 expect(
46 resolveThreadRouteTarget({
47 environmentId: "env-1",
48 threadId: "thread-1",
49 }),
50 ).toEqual({
51 kind: "server",
52 threadRef: {
53 environmentId: "env-1",
54 threadId: "thread-1",
55 },
56 });
57​
58 expect(
59 resolveThreadRouteTarget({
60 draftId: "draft-1",
61 }),
62 ).toEqual({
63 kind: "draft",
64 draftId: "draft-1",
65 });
66 });
67});