Files
gridpilot.gg/adapters/events/InMemoryEventPublisher.ts
Marc Mintel fb1221701d
Some checks failed
Contract Testing / contract-tests (push) Failing after 6m7s
Contract Testing / contract-snapshot (push) Failing after 4m46s
add tests
2026-01-22 11:52:42 +01:00

40 lines
1.2 KiB
TypeScript

import {
DashboardEventPublisher,
DashboardAccessedEvent,
DashboardErrorEvent,
} from '../../core/dashboard/application/ports/DashboardEventPublisher';
export class InMemoryEventPublisher implements DashboardEventPublisher {
private dashboardAccessedEvents: DashboardAccessedEvent[] = [];
private dashboardErrorEvents: DashboardErrorEvent[] = [];
private shouldFail: boolean = false;
async publishDashboardAccessed(event: DashboardAccessedEvent): Promise<void> {
if (this.shouldFail) throw new Error('Event publisher failed');
this.dashboardAccessedEvents.push(event);
}
async publishDashboardError(event: DashboardErrorEvent): Promise<void> {
if (this.shouldFail) throw new Error('Event publisher failed');
this.dashboardErrorEvents.push(event);
}
getDashboardAccessedEventCount(): number {
return this.dashboardAccessedEvents.length;
}
getDashboardErrorEventCount(): number {
return this.dashboardErrorEvents.length;
}
clear(): void {
this.dashboardAccessedEvents = [];
this.dashboardErrorEvents = [];
this.shouldFail = false;
}
setShouldFail(shouldFail: boolean): void {
this.shouldFail = shouldFail;
}
}