/** * In-memory fake of Ably's `BaseRealtime` surface used by AblyClient tests. * * Only models the parts the chat layer actually touches: * - `connection` with `state` + `.on(event, handler)` events * for "connected" | "disconnected" | "suspended" | "failed" * - `auth.clientId`, `auth.authorize(token)` * - `channels.get(name)` returning a FakeRealtimeChannel with attach/detach, * subscribe/unsubscribe/publish, and a `state` machine that can be driven * programmatically. * - `channels.release(name)` * - `connect()` / `close()` * * The Ably typings are wide and surface lots of unrelated APIs; rather than * fight them we expose this fake with its own minimal types and only cast * to `BaseRealtime` at the construction site. */ import type { ChannelState, ChannelStateChange, TokenRequest } from "ably"; import type { BaseRealtime } from "ably/modular"; type Handler = (event: T) => void; export declare class FakeRealtimeChannel { readonly name: string; state: ChannelState; readonly subscriptions: Map void)[]>; readonly published: Array<{ event: string; data: unknown; }>; attachCalls: number; detachCalls: number; private _stateListeners; private _attachResolvers; constructor(name: string); attach(): Promise; /** Test helper to resolve a pending attach. */ resolveAttach(): void; /** Test helper to reject a pending attach. */ rejectAttach(err: unknown): void; detach(): Promise; setState(next: ChannelState): void; on(handler: Handler): void; off(handler: Handler): void; subscribe(event: string, callback: (msg: { data: unknown; }) => void): void; unsubscribe(): void; publish(event: string, data: unknown): Promise; /** Drive an inbound message for tests. */ emit(event: string, data: unknown): void; } export declare class FakeAuth { clientId: string | null; authorizeCalls: number; shouldFailAuthorize: boolean; authorize(token: TokenRequest): Promise; } export type ConnectionState = "initialized" | "connecting" | "connected" | "disconnected" | "suspended" | "closing" | "closed" | "failed"; export declare class FakeConnection { state: ConnectionState; private _listeners; on(event: string, handler: Handler): void; emit(event: ConnectionState): void; } export declare class FakeChannels { releaseCalls: string[]; private _registry; get(name: string): FakeRealtimeChannel; release(name: string): void; } export declare class FakeBaseRealtime { connectCalls: number; closeCalls: number; readonly connection: FakeConnection; readonly auth: FakeAuth; readonly channels: FakeChannels; constructor(); connect(): void; close(): void; /** Cast helper to satisfy AblyClient's constructor signature. */ asBaseRealtime(): BaseRealtime; } export {};