Open History to see the last commit
1import type { EnvironmentId, ScopedThreadRef, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { resolveThreadLink } from "./threadLink";
5
6const ref = {
7 environmentId: "env_local" as EnvironmentId,
8 threadId: "thr_123" as ThreadId,
9} as ScopedThreadRef;
10
11describe("resolveThreadLink", () => {
12 it("uses the browser origin the client is served from", () => {
13 expect(
14 resolveThreadLink({
15 clientOrigin: "https://app.t3.codes",
16 environmentHttpBaseUrl: "http://192.168.1.4:3773",
17 ref,
18 }),
19 ).toBe("https://app.t3.codes/env_local/thr_123");
20 });
21
22 it("falls back to the environment server when the origin is not a web origin", () => {
23 expect(
24 resolveThreadLink({
25 clientOrigin: "t3code://app",
26 environmentHttpBaseUrl: "http://127.0.0.1:3773/",
27 ref,
28 }),
29 ).toBe("http://127.0.0.1:3773/env_local/thr_123");
30 });
31
32 it("returns null when neither the client nor the environment has a web origin", () => {
33 expect(
34 resolveThreadLink({ clientOrigin: "t3code://app", environmentHttpBaseUrl: null, ref }),
35 ).toBeNull();
36 expect(
37 resolveThreadLink({ clientOrigin: null, environmentHttpBaseUrl: "not a url", ref }),
38 ).toBeNull();
39 });
40
41 it("drops any path the environment base URL carries", () => {
42 expect(
43 resolveThreadLink({
44 clientOrigin: null,
45 environmentHttpBaseUrl: "https://tunnel.example.com/base/",
46 ref,
47 }),
48 ).toBe("https://tunnel.example.com/env_local/thr_123");
49 });
50});