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

connection.test.ts

56 lines1.5 KB

1import { afterEach, describe, expect, it, vi } from "vite-plus/test";
2import { EnvironmentId } from "@t3tools/contracts";
3​
4import { toStableSavedRemoteConnection } from "./connection";
5​
6const mobilePlatform = vi.hoisted(() => ({ OS: "ios" as "ios" | "android" }));
7const mobileDevice = vi.hoisted(() => ({
8 deviceType: 1,
9 DeviceType: {
10 UNKNOWN: 0,
11 PHONE: 1,
12 TABLET: 2,
13 DESKTOP: 3,
14 TV: 4,
15 },
16 osVersion: "18.4.1",
17 modelName: "iPhone 15 Pro",
18}));
19​
20vi.mock("./runtime", () => ({
21 runtime: {
22 runPromise: vi.fn(),
23 },
24}));
25​
26vi.mock("react-native", () => ({
27 Platform: mobilePlatform,
28}));
29​
30vi.mock("expo-device", () => mobileDevice);
31​
32describe("mobile remote connection records", () => {
33 afterEach(() => {
34 mobilePlatform.OS = "ios";
35 mobileDevice.deviceType = mobileDevice.DeviceType.PHONE;
36 mobileDevice.osVersion = "18.4.1";
37 mobileDevice.modelName = "iPhone 15 Pro";
38 });
39​
40 it("drops short-lived managed environment credentials from stable records", () => {
41 const connection = {
42 environmentId: EnvironmentId.make("environment-1"),
43 environmentLabel: "Desktop",
44 pairingUrl: "https://desktop.example/",
45 displayUrl: "https://desktop.example/",
46 httpBaseUrl: "https://desktop.example/",
47 wsBaseUrl: "wss://desktop.example/",
48 bearerToken: null,
49 authenticationMethod: "dpop",
50 dpopAccessToken: "short-lived-token",
51 relayManaged: true,
52 } as const;
53​
54 expect(toStableSavedRemoteConnection(connection)).not.toHaveProperty("dpopAccessToken");
55 });
56});