import { StreamChat } from 'stream-chat' /* eslint-disable @typescript-eslint/no-explicit-any */ /** A participant in the mock conversation. */ export interface MockMessagingUser { id: string name?: string image?: string } export interface CreateMockStreamChatClientOptions { /** * Also replace the connection-dependent client methods (`connectUser`, * `disconnectUser`, `userMuteStatus`) with offline no-ops. Needed when the * client drives a flow that would otherwise open a WebSocket or throw * "Make sure to await connectUser() first." offline. Direct `` * rendering (e.g. component stories) does not need this. */ stubConnection?: boolean } /** * Builds an offline `StreamChat` for mocks and stories: a real client on a * throwaway api key with `userID`/`user` set so `` treats it as * connected without a backend. The single place that knows how to construct a * connectionless Stream client, so a stream-chat version bump only needs * updating here rather than in each mock surface. */ export function createMockStreamChatClient( user: MockMessagingUser, { stubConnection = false }: CreateMockStreamChatClientOptions = {} ): StreamChat { const client = new StreamChat('mock-api-key', { allowServerSideConnect: true, }) client.userID = user.id client.user = user as any if (stubConnection) { client.connectUser = async () => ({ me: user }) as any client.disconnectUser = async () => undefined client.userMuteStatus = (() => false) as any } return client } /* eslint-enable @typescript-eslint/no-explicit-any */