main
ts 81 lines 2.38 KB
Raw
1 import { describe, expect, it } from "vitest";
2
3 import {
4 buildTunnelCommand,
5 buildTunnelDisplayCommand,
6 buildTunnelPreviewURL,
7 } from "@/lib/tunnelCommand";
8
9 describe("tunnelCommand", () => {
10 it("keeps copied unix commands flat and directly pasteable", () => {
11 const options = {
12 currentOrigin: "https://localhost:4017",
13 target: "3000",
14 name: "My App",
15 nameSeed: "web_portal",
16 relayUrls: ["https://localhost:4017"],
17 discovery: true,
18 thumbnailURL: "",
19 os: "unix" as const,
20 };
21
22 const command = buildTunnelCommand(options);
23
24 expect(command).toBe(
25 [
26 "curl -ksSL https://localhost:4017/api/install.sh | bash",
27 "portal expose 3000 --name my-app --relays https://localhost:4017",
28 ].join("\n")
29 );
30 expect(command).not.toContain(" \\\n");
31 expect(command).not.toContain("\n --name");
32 });
33
34 it("keeps display and copied commands flat", () => {
35 const options = {
36 currentOrigin: "https://relay.example.com",
37 target: "localhost:3000",
38 name: "my-app",
39 nameSeed: "web_portal",
40 relayUrls: ["https://relay.example.com"],
41 discovery: false,
42 thumbnailURL: "https://example.com/thumb.png",
43 os: "windows" as const,
44 };
45
46 expect(buildTunnelCommand(options)).toBe(
47 [
48 `$ProgressPreference = 'SilentlyContinue'`,
49 `irm https://relay.example.com/api/install.ps1 | iex`,
50 `portal expose localhost:3000 --name my-app --relays https://relay.example.com --discovery=false --thumbnail https://example.com/thumb.png`,
51 ].join("\n")
52 );
53 expect(buildTunnelDisplayCommand(options)).toBe(
54 [
55 `$ProgressPreference = 'SilentlyContinue'`,
56 `irm https://relay.example.com/api/install.ps1 | iex`,
57 `portal expose localhost:3000 --name my-app --relays https://relay.example.com --discovery=false --thumbnail https://example.com/thumb.png`,
58 ].join("\n")
59 );
60 });
61
62 it("uses the relay root host for preview URLs instead of a placeholder host", () => {
63 expect(
64 buildTunnelPreviewURL(
65 "https://localhost:4017",
66 "my-app",
67 "3000",
68 "web_portal"
69 )
70 ).toBe("https://my-app.localhost");
71
72 expect(
73 buildTunnelPreviewURL(
74 "https://portal.example.com",
75 "my-app",
76 "3000",
77 "web_portal"
78 )
79 ).toBe("https://my-app.portal.example.com");
80 });
81 });