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

peerLinks.test.ts

52 lines1.6 KB

1import { EnvironmentId, type PeerLinkSummary } from "@t3tools/contracts";
2import * as DateTime from "effect/DateTime";
3import { describe, expect, it } from "vite-plus/test";
4​
5import { linkThroughRoutes } from "./peerLinks.ts";
6​
7const now = DateTime.makeUnsafe("2026-11-20T00:00:00.000Z");
8const id = (value: string) => EnvironmentId.make(value);
9​
10const link = (target: string, overrides: Partial<PeerLinkSummary> = {}): PeerLinkSummary => ({
11 environmentId: id(target),
12 label: target,
13 urls: [`https://${target}.example`],
14 access: "full-access",
15 status: "reachable",
16 linkedAt: now,
17 lastReachedAt: now,
18 lastError: null,
19 expiresAt: DateTime.makeUnsafe("2026-12-20T00:00:00.000Z"),
20 ...overrides,
21});
22​
23describe("linkThroughRoutes", () => {
24 it("offers only machines another environment reaches over a full-access link that answers", () => {
25 const routes = linkThroughRoutes({
26 sourceEnvironmentId: id("source"),
27 hosts: [
28 { environmentId: id("source"), links: [link("own")] },
29 {
30 environmentId: id("via"),
31 links: [
32 link("open"),
33 link("source"),
34 link("supervised", { access: "approval-required" }),
35 link("down", { status: "unreachable" }),
36 link("lapsed", { expiresAt: now }),
37 ],
38 },
39 { environmentId: id("later"), links: [link("open")] },
40 ],
41 now,
42 });
43 expect([...routes.values()]).toEqual([
44 {
45 viaEnvironmentId: id("via"),
46 environmentId: id("open"),
47 label: "open",
48 urls: ["https://open.example"],
49 },
50 ]);
51 });
52});