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

knownEnvironment.test.ts

52 lines1.7 KB

1import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { createKnownEnvironment } from "./knownEnvironment.ts";
5import {
6 parseScopedProjectKey,
7 parseScopedThreadKey,
8 scopedProjectKey,
9 scopedThreadKey,
10 scopeProjectRef,
11 scopeThreadRef,
12} from "./scoped.ts";
13​
14describe("known environment bootstrap helpers", () => {
15 it("creates known environments from explicit server base urls", () => {
16 expect(
17 createKnownEnvironment({
18 label: "Remote environment",
19 target: {
20 httpBaseUrl: "https://remote.example.com",
21 wsBaseUrl: "wss://remote.example.com",
22 },
23 }),
24 ).toEqual({
25 id: "ws:Remote environment",
26 label: "Remote environment",
27 source: "manual",
28 target: {
29 httpBaseUrl: "https://remote.example.com",
30 wsBaseUrl: "wss://remote.example.com",
31 },
32 });
33 });
34});
35​
36describe("scoped refs", () => {
37 const environmentId = EnvironmentId.make("environment-test");
38 const projectRef = scopeProjectRef(environmentId, ProjectId.make("project-1"));
39 const threadRef = scopeThreadRef(environmentId, ThreadId.make("thread-1"));
40​
41 it("builds stable scoped project and thread keys", () => {
42 expect(scopedProjectKey(projectRef)).toBe("environment-test:project-1");
43 expect(scopedThreadKey(threadRef)).toBe("environment-test:thread-1");
44 });
45​
46 it("parses scoped project and thread keys back into refs", () => {
47 expect(parseScopedProjectKey("environment-test:project-1")).toEqual(projectRef);
48 expect(parseScopedThreadKey("environment-test:thread-1")).toEqual(threadRef);
49 expect(parseScopedProjectKey("bad-key")).toBeNull();
50 expect(parseScopedThreadKey("bad-key")).toBeNull();
51 });
52});