1import { describe, expect, it } from "vite-plus/test";
2
3import { buildPairingUrl, extractPairingUrlFromQrPayload, parsePairingUrl } from "./pairing";
4
5describe("buildPairingUrl", () => {
6 it("uses HTTP for a schemeless IP address", () => {
7 expect(buildPairingUrl("192.168.1.100:3773", "pairing-token")).toBe(
8 "http://192.168.1.100:3773/#token=pairing-token",
9 );
10 });
11
12 it("keeps HTTPS as the default for a schemeless hostname", () => {
13 expect(buildPairingUrl("remote.example.com", "pairing-token")).toBe(
14 "https://remote.example.com/#token=pairing-token",
15 );
16 });
17
18 it("preserves an explicit scheme for an IP address", () => {
19 expect(buildPairingUrl("https://192.168.1.100:3773", "pairing-token")).toBe(
20 "https://192.168.1.100:3773/#token=pairing-token",
21 );
22 });
23});
24
25describe("extractPairingUrlFromQrPayload", () => {
26 it("unwraps mobile deep links that carry an encoded pairing url", () => {
27 expect(
28 extractPairingUrlFromQrPayload(
29 "t3code://pair?pairingUrl=https%3A%2F%2Fremote.example.com%2Fpair%23token%3Dpairing-token",
30 ),
31 ).toBe("https://remote.example.com/pair#token=pairing-token");
32 });
33});
34
35describe("parsePairingUrl", () => {
36 it("reads hosted pairing links into backend host fields", () => {
37 expect(
38 parsePairingUrl(
39 "https://app.t3.codes/pair?host=https%3A%2F%2Fdesktop.tailnet.ts.net%2F#token=pairing-token",
40 ),
41 ).toEqual({
42 host: "https://desktop.tailnet.ts.net",
43 code: "pairing-token",
44 });
45 });
46});