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

connection.test.ts

42 lines1.3 KB

1import { describe, expect, it, vi } from "vitest";
2​
3import { mobileAuthClientMetadata, redactPairingCredential } from "./connection";
4​
5vi.mock("./runtime", () => ({
6 mobileRemoteHttpRuntime: {
7 runPromise: vi.fn(),
8 },
9}));
10​
11vi.mock("react-native", () => ({
12 Platform: {
13 OS: "ios",
14 },
15}));
16​
17describe("mobile remote connection records", () => {
18 it("identifies mobile token exchanges for authorized-client presentation", () => {
19 expect(mobileAuthClientMetadata()).toEqual({
20 label: "T3 Code Mobile",
21 deviceType: "mobile",
22 os: "iOS",
23 });
24 });
25​
26 it("removes one-time bootstrap credentials before persisting pairing URLs", () => {
27 expect(redactPairingCredential("https://desktop.example/#token=bootstrap-token")).toBe(
28 "https://desktop.example/",
29 );
30 expect(redactPairingCredential("https://desktop.example/?token=bootstrap-token")).toBe(
31 "https://desktop.example/",
32 );
33 });
34​
35 it("removes hosted pairing credentials while keeping the advertised host", () => {
36 expect(
37 redactPairingCredential(
38 "https://app.t3.codes/pair?host=https%3A%2F%2Fdesktop.example&token=bootstrap-token&label=Desktop",
39 ),
40 ).toBe("https://app.t3.codes/pair?host=https%3A%2F%2Fdesktop.example&label=Desktop");
41 });
42});