@codeforbreakfast/eventsourcing-testing-contracts
Version:
Comprehensive testing utilities for event sourcing implementations - Test contracts for transport and protocol implementations with mock utilities and test data generators
60 lines • 2.75 kB
TypeScript
/**
* Test Utilities for Transport Testing
*
* This module provides common test utilities, mock implementations,
* and test data generators for transport testing scenarios.
*/
import { Effect, Stream, Chunk, Scope } from 'effect';
import type { TransportMessage, ConnectedTransportTestInterface, ConnectionState } from './test-layer-interfaces';
/**
* Generates unique message IDs for testing
*/
export declare const generateMessageId: () => string;
/**
* Make a test transport message
*/
export declare const makeTestTransportMessage: <TPayload = unknown>(type: string, payload: TPayload, options?: {
id?: string;
metadata?: Record<string, unknown>;
}) => TransportMessage;
/**
* Mock transport state for testing
*/
export interface MockTransportState {
readonly messages: readonly TransportMessage[];
readonly subscriptions: readonly ((message: TransportMessage) => void)[];
readonly isConnected: boolean;
readonly connectionStateSubscribers: readonly ((state: ConnectionState) => void)[];
}
/**
* Creates a mock transport for testing
*/
export declare const makeMockTransport: () => Effect.Effect<ConnectedTransportTestInterface, never, Scope.Scope>;
/**
* Waits for a condition to become true within a timeout period
*/
export declare const waitForCondition: <E = never>(condition: () => Effect.Effect<boolean, E, never>, timeoutMs?: number, pollIntervalMs?: number) => Effect.Effect<void, E | "timeout", never>;
/**
* Expects an effect to fail with a specific error type
*/
export declare const expectError: <A, E>(effect: Effect.Effect<A, E, never>, errorPredicate: (error: E) => boolean) => Effect.Effect<E, Error, never>;
/**
* Collects all values from a stream within a timeout period
*/
export declare const collectStreamWithTimeout: <A, E>(stream: Stream.Stream<A, E, never>, timeoutMs?: number) => Effect.Effect<Chunk.Chunk<A>, E | "timeout", never>;
/**
* Default implementation of waitForConnectionState for testing
* Waits for a specific connection state to be emitted
*/
export declare const waitForConnectionState: (connectionStateStream: Stream.Stream<ConnectionState, never, never>, expectedState: ConnectionState, timeoutMs?: number) => Effect.Effect<void, Error, never>;
/**
* Default implementation of collectMessages for testing
* Collects a specific number of messages from a stream
*/
export declare const collectMessages: <T>(stream: Stream.Stream<T, never, never>, count: number, timeoutMs?: number) => Effect.Effect<T[], Error, never>;
/**
* Default implementation of makeTestMessage for testing
* Creates a test message with unique ID
*/
export declare const makeTestMessage: (type: string, payload: unknown) => TransportMessage;
//# sourceMappingURL=test-utilities.d.ts.map