1import {
2 BearerConnectionTarget,
3 RelayConnectionTarget,
4 type ConnectionCatalogEntry,
5} from "@t3tools/client-runtime/connection";
6import { EnvironmentId } from "@t3tools/contracts";
7import * as Option from "effect/Option";
8import { describe, expect, it } from "vite-plus/test";
9
10import { shouldEnableCloudAuth } from "./connectionService";
11
12const direct: ConnectionCatalogEntry = {
13 target: new BearerConnectionTarget({
14 environmentId: EnvironmentId.make("machine"),
15 connectionId: "direct",
16 label: "Laptop",
17 }),
18 profile: Option.none(),
19 enabled: true,
20};
21
22describe("optional mobile T3 Connect", () => {
23 it("keeps fresh, direct, and self-hosted sessions independent of cloud sign-in", () => {
24 expect(shouldEnableCloudAuth(undefined, [])).toBe(false);
25 expect(shouldEnableCloudAuth(undefined, [direct])).toBe(false);
26 expect(shouldEnableCloudAuth("self-hosted", [direct])).toBe(false);
27 expect(shouldEnableCloudAuth("t3-connect", [])).toBe(true);
28 });
29
30 it("restores existing cloud routes even when a direct route is preferred", () => {
31 const entry: ConnectionCatalogEntry = {
32 ...direct,
33 alternateRoutes: [
34 {
35 target: new RelayConnectionTarget({
36 environmentId: direct.target.environmentId,
37 label: "Laptop",
38 }),
39 profile: Option.none(),
40 },
41 ],
42 };
43 expect(shouldEnableCloudAuth(undefined, [entry])).toBe(true);
44 expect(shouldEnableCloudAuth("self-hosted", [entry])).toBe(true);
45 });
46});