feat(caprover): allow to trigger an application update
+ added test coverage
This commit is contained in:
44
domain/testing/TestApp.ts
Normal file
44
domain/testing/TestApp.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import AppProjections from "../AppProjections";
|
||||
import AppQueries from "../AppQueries";
|
||||
import EventStore from "../EventStore";
|
||||
|
||||
export class TestApp {
|
||||
readonly eventStore: InMemoryEventStore = new InMemoryEventStore();
|
||||
readonly projections: AppProjections = new AppProjections();
|
||||
readonly queries: AppQueries = new AppQueries(this.projections);
|
||||
|
||||
constructor(history: DomainEvent<any>[] = []) {
|
||||
this.projections.getAll().forEach((projection) => {
|
||||
this.eventStore.subscribe(projection);
|
||||
});
|
||||
|
||||
for (const event of history) {
|
||||
this.eventStore.append(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
class InMemoryEventStore implements EventStore {
|
||||
private handlers: DomainProjection[] = [];
|
||||
private readonly events: DomainEvent<any>[] = [];
|
||||
|
||||
async append(event: DomainEvent<any>): Promise<void> {
|
||||
this.events.push(event);
|
||||
for (const handler of this.handlers) {
|
||||
handler.handle(event);
|
||||
}
|
||||
}
|
||||
|
||||
subscribe(projection: DomainProjection): void {
|
||||
this.handlers.push(projection);
|
||||
}
|
||||
|
||||
async replay(): Promise<void> {
|
||||
throw new Error(
|
||||
"Replay is not relevant for InMemoryEventStore. Use append instead."
|
||||
);
|
||||
}
|
||||
|
||||
getAllEvents(): DomainEvent<any>[] {
|
||||
return this.events;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user