44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import {
|
|
extractPairingUrlFromQrPayload,
|
|
PairingQrPayloadEmptyError,
|
|
parsePairingUrl,
|
|
} from "./pairing";
|
|
|
|
describe("extractPairingUrlFromQrPayload", () => {
|
|
it("trims raw pairing urls from qr payloads", () => {
|
|
expect(
|
|
extractPairingUrlFromQrPayload(" https://remote.example.com/pair#token=pairing-token "),
|
|
).toBe("https://remote.example.com/pair#token=pairing-token");
|
|
});
|
|
|
|
it("unwraps mobile deep links that carry an encoded pairing url", () => {
|
|
expect(
|
|
extractPairingUrlFromQrPayload(
|
|
"t3code://pair?pairingUrl=https%3A%2F%2Fremote.example.com%2Fpair%23token%3Dpairing-token",
|
|
),
|
|
).toBe("https://remote.example.com/pair#token=pairing-token");
|
|
});
|
|
|
|
it("rejects empty qr payloads", () => {
|
|
expect(() => extractPairingUrlFromQrPayload(" ")).toThrowError(PairingQrPayloadEmptyError);
|
|
expect(() => extractPairingUrlFromQrPayload(" ")).toThrowError(
|
|
"Scanned QR code did not contain a pairing URL.",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("parsePairingUrl", () => {
|
|
it("reads hosted pairing links into backend host fields", () => {
|
|
expect(
|
|
parsePairingUrl(
|
|
"https://app.t3.codes/pair?host=https%3A%2F%2Fdesktop.tailnet.ts.net%2F#token=pairing-token",
|
|
),
|
|
).toEqual({
|
|
host: "https://desktop.tailnet.ts.net",
|
|
code: "pairing-token",
|
|
});
|
|
});
|
|
});
|