autotel
Version:
Write Once, Observe Anywhere
111 lines (107 loc) • 2.9 kB
TypeScript
import { EventAttributes, FunnelStatus, OutcomeStatus } from './event-subscriber.js';
/**
* Testing utilities for Events
*
* Provides in-memory collection of events for testing purposes.
*/
interface EventData {
event: string;
attributes?: EventAttributes;
service: string;
timestamp: number;
}
interface EventsFunnelStep {
funnel: string;
status: FunnelStatus;
attributes?: EventAttributes;
service: string;
timestamp: number;
}
interface EventsOutcome {
operation: string;
status: OutcomeStatus;
attributes?: EventAttributes;
service: string;
timestamp: number;
}
interface EventsValue {
metric: string;
value: number;
attributes?: EventAttributes;
service: string;
timestamp: number;
}
/**
* In-memory events collector for testing
*/
interface EventCollector {
/** Get all collected events */
getEvents(): EventData[];
/** Get all collected funnel steps */
getFunnelSteps(): EventsFunnelStep[];
/** Get all collected outcomes */
getOutcomes(): EventsOutcome[];
/** Get all collected values */
getValues(): EventsValue[];
/** Clear all collected events */
clear(): void;
/** Record an event (internal use) */
recordEvent(event: EventData): void;
/** Record a funnel step (internal use) */
recordFunnelStep(step: EventsFunnelStep): void;
/** Record an outcome (internal use) */
recordOutcome(outcome: EventsOutcome): void;
/** Record a value (internal use) */
recordValue(value: EventsValue): void;
}
/**
* Create an in-memory events collector for testing
*
* @example
* ```typescript
* const collector = createEventCollector()
*
* const events = new Event('test-service', { collector })
* events.trackEvent('application.submitted', { jobId: '123' })
*
* const event =collector.getEvents()
* expect(events).toHaveLength(1)
* expect(events[0].event).toBe('application.submitted')
* ```
*/
declare function createEventCollector(): EventCollector;
/**
* Assert that an events event was tracked
*
* @example
* ```typescript
* assertEventTracked({
* collector,
* eventName: 'application.submitted',
* attributes: { jobId: '123' }
* })
* ```
*/
declare function assertEventTracked(options: {
collector: EventCollector;
eventName: string;
attributes?: Record<string, unknown>;
}): void;
/**
* Assert that an outcome was tracked
*
* @example
* ```typescript
* assertOutcomeTracked({
* collector,
* operation: 'email.delivery',
* status: 'success'
* })
* ```
*/
declare function assertOutcomeTracked(options: {
collector: EventCollector;
operation: string;
status: 'success' | 'failure' | 'partial';
}): void;
export { type EventCollector, type EventData, type EventsFunnelStep, type EventsOutcome, type EventsValue, assertEventTracked, assertOutcomeTracked, createEventCollector };