1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/test/fixtures/fake-event-store.ts

64 lines
1.5 KiB
TypeScript
Raw Normal View History

import { IEventStore } from '../../lib/types/stores/event-store';
import { IEvent } from '../../lib/types/events';
import { AnyEventEmitter } from '../../lib/util/anyEventEmitter';
class FakeEventStore extends AnyEventEmitter implements IEventStore {
events: IEvent[];
constructor() {
super();
this.setMaxListeners(0);
this.events = [];
}
store(event: IEvent): Promise<void> {
this.events.push(event);
this.emit(event.type, event);
return Promise.resolve();
}
batchStore(events: IEvent[]): Promise<void> {
events.forEach((event) => {
this.events.push(event);
this.emit(event.type, event);
});
return Promise.resolve();
}
async getEvents(): Promise<IEvent[]> {
return this.events;
}
async delete(key: number): Promise<void> {
this.events.splice(
this.events.findIndex((t) => t.id === key),
1,
);
}
async deleteAll(): Promise<void> {
this.events = [];
}
destroy(): void {}
async exists(key: number): Promise<boolean> {
return this.events.some((e) => e.id === key);
}
async get(key: number): Promise<IEvent> {
return this.events.find((e) => e.id === key);
}
async getAll(): Promise<IEvent[]> {
return this.events;
}
async searchEvents(): Promise<IEvent[]> {
throw new Error('Method not implemented.');
}
}
module.exports = FakeEventStore;
export default FakeEventStore;