@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 47 lines 1.43 KB
Raw
1 import { managedRelaySessionAtom } from "@t3tools/client-runtime/relay";
2 import * as Effect from "effect/Effect";
3 import { afterEach, describe, expect, it, vi } from "vite-plus/test";
4
5 import { appAtomRegistry } from "../rpc/atomRegistry";
6 import {
7 activateManagedRelayAuthentication,
8 deactivateManagedRelayAuthentication,
9 } from "./managedAuth";
10
11 vi.mock("@clerk/react", () => ({
12 useClerk: vi.fn(),
13 }));
14
15 vi.mock("../lib/runtime", () => ({
16 runtime: {
17 runPromiseExit: vi.fn(),
18 },
19 }));
20
21 vi.mock("../connection/catalog", () => ({
22 environmentCatalog: {
23 removeRelayEnvironments: {},
24 },
25 }));
26
27 afterEach(() => {
28 deactivateManagedRelayAuthentication();
29 });
30
31 describe("managed relay authentication", () => {
32 it("clears all token access synchronously before account cleanup can fail", async () => {
33 activateManagedRelayAuthentication("account-1", async () => "account-1-token");
34 expect(appAtomRegistry.get(managedRelaySessionAtom)?.accountId).toBe("account-1");
35 const token = await Effect.fromNullishOr(appAtomRegistry.get(managedRelaySessionAtom)).pipe(
36 Effect.flatMap((session) => session.readClerkToken()),
37 Effect.runPromise,
38 );
39 expect(token).toBe("account-1-token");
40
41 deactivateManagedRelayAuthentication();
42 const cleanup = Promise.reject(new Error("Persistence removal failed.")).catch(() => undefined);
43
44 expect(appAtomRegistry.get(managedRelaySessionAtom)).toBeNull();
45 await cleanup;
46 });
47 });