Open History to see the last commit
1import { resolveRemotePairingTarget } from "@t3tools/shared/remote";
2import { describe, expect, it } from "vite-plus/test";
3
4import { buildPairingUrl, extractPairingUrlFromQrPayload, parsePairingUrl } from "./pairing";
5
6describe("buildPairingUrl", () => {
7 it("uses HTTP for a schemeless IP address", () => {
8 expect(buildPairingUrl("192.168.1.100:3773", "pairing-token")).toBe(
9 "http://192.168.1.100:3773/#token=pairing-token",
10 );
11 });
12
13 it("keeps HTTPS as the default for a schemeless hostname", () => {
14 expect(buildPairingUrl("remote.example.com", "pairing-token")).toBe(
15 "https://remote.example.com/#token=pairing-token",
16 );
17 });
18
19 it("preserves an explicit scheme for an IP address", () => {
20 expect(buildPairingUrl("https://192.168.1.100:3773", "pairing-token")).toBe(
21 "https://192.168.1.100:3773/#token=pairing-token",
22 );
23 });
24
25 it("pairs with the address's own origin when the address carries a query", () => {
26 const pairingUrl = buildPairingUrl(
27 "https://remote.example.com/?host=https%3A%2F%2Fother.example.com",
28 "pairing-token",
29 );
30
31 expect(pairingUrl).toBe("https://remote.example.com/#token=pairing-token");
32 expect(resolveRemotePairingTarget({ pairingUrl })).toEqual({
33 credential: "pairing-token",
34 httpBaseUrl: "https://remote.example.com/",
35 wsBaseUrl: "wss://remote.example.com/",
36 });
37 });
38});
39
40describe("extractPairingUrlFromQrPayload", () => {
41 it("unwraps mobile deep links that carry an encoded pairing url", () => {
42 expect(
43 extractPairingUrlFromQrPayload(
44 "t3code://pair?pairingUrl=https%3A%2F%2Fremote.example.com%2Fpair%23token%3Dpairing-token",
45 ),
46 ).toBe("https://remote.example.com/pair#token=pairing-token");
47 });
48});
49
50describe("parsePairingUrl", () => {
51 it("reads hosted pairing links into backend host fields", () => {
52 expect(
53 parsePairingUrl(
54 "https://app.t3.codes/pair?host=https%3A%2F%2Fdesktop.tailnet.ts.net%2F#token=pairing-token",
55 ),
56 ).toEqual({
57 host: "https://desktop.tailnet.ts.net",
58 code: "pairing-token",
59 });
60 });
61});