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

pairing.test.ts

43 lines1.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 extractPairingUrlFromQrPayload,
5 PairingQrPayloadEmptyError,
6 parsePairingUrl,
7} from "./pairing";
8​
9describe("extractPairingUrlFromQrPayload", () => {
10 it("trims raw pairing urls from qr payloads", () => {
11 expect(
12 extractPairingUrlFromQrPayload(" https://remote.example.com/pair#token=pairing-token "),
13 ).toBe("https://remote.example.com/pair#token=pairing-token");
14 });
15​
16 it("unwraps mobile deep links that carry an encoded pairing url", () => {
17 expect(
18 extractPairingUrlFromQrPayload(
19 "t3code://pair?pairingUrl=https%3A%2F%2Fremote.example.com%2Fpair%23token%3Dpairing-token",
20 ),
21 ).toBe("https://remote.example.com/pair#token=pairing-token");
22 });
23​
24 it("rejects empty qr payloads", () => {
25 expect(() => extractPairingUrlFromQrPayload(" ")).toThrowError(PairingQrPayloadEmptyError);
26 expect(() => extractPairingUrlFromQrPayload(" ")).toThrowError(
27 "Scanned QR code did not contain a pairing URL.",
28 );
29 });
30});
31​
32describe("parsePairingUrl", () => {
33 it("reads hosted pairing links into backend host fields", () => {
34 expect(
35 parsePairingUrl(
36 "https://app.t3.codes/pair?host=https%3A%2F%2Fdesktop.tailnet.ts.net%2F#token=pairing-token",
37 ),
38 ).toEqual({
39 host: "https://desktop.tailnet.ts.net",
40 code: "pairing-token",
41 });
42 });
43});