| 1 | import { afterEach, describe, expect, it, vi } from "vite-plus/test"; |
| 2 | |
| 3 | import { resolveDesktopPairingUrl, resolveHostedPairingUrl } from "./pairingUrls"; |
| 4 | |
| 5 | describe("settings pairing URL helpers", () => { |
| 6 | afterEach(() => { |
| 7 | vi.unstubAllEnvs(); |
| 8 | }); |
| 9 | |
| 10 | it("uses direct backend pairing URLs for HTTP endpoints", () => { |
| 11 | expect(resolveHostedPairingUrl("http://192.168.1.44:3773", "PAIRCODE")).toBeNull(); |
| 12 | expect(resolveDesktopPairingUrl("http://192.168.1.44:3773", "PAIRCODE")).toBe( |
| 13 | "http://192.168.1.44:3773/pair#token=PAIRCODE", |
| 14 | ); |
| 15 | }); |
| 16 | |
| 17 | it("keeps the environment prefix in direct pairing links", () => { |
| 18 | expect( |
| 19 | resolveDesktopPairingUrl("https://hub.example/prefix/environments/one/", "PAIRCODE"), |
| 20 | ).toBe("https://hub.example/prefix/environments/one/pair#token=PAIRCODE"); |
| 21 | }); |
| 22 | |
| 23 | it("uses hosted pairing URLs for HTTPS endpoints", () => { |
| 24 | vi.stubEnv("VITE_HOSTED_APP_URL", "https://preview.t3.codes"); |
| 25 | |
| 26 | expect(resolveHostedPairingUrl("https://host.tailnet.example.ts.net:3773", "PAIRCODE")).toBe( |
| 27 | "https://preview.t3.codes/pair?host=https%3A%2F%2Fhost.tailnet.example.ts.net%3A3773#token=PAIRCODE", |
| 28 | ); |
| 29 | }); |
| 30 | }); |