2021-08-12 15:04:37 +02:00
|
|
|
import EventEmitter from 'events';
|
|
|
|
import { IEventStore } from '../../lib/types/stores/event-store';
|
|
|
|
import { IEvent } from '../../lib/types/model';
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
class FakeEventStore extends EventEmitter implements IEventStore {
|
2021-04-27 20:47:11 +02:00
|
|
|
events: IEvent[];
|
2021-01-19 10:42:45 +01:00
|
|
|
|
|
|
|
constructor() {
|
2021-08-12 15:04:37 +02:00
|
|
|
super();
|
2021-01-19 10:42:45 +01:00
|
|
|
this.setMaxListeners(0);
|
|
|
|
this.events = [];
|
|
|
|
}
|
|
|
|
|
2021-04-27 20:47:11 +02:00
|
|
|
store(event: IEvent): Promise<void> {
|
2021-01-19 10:42:45 +01:00
|
|
|
this.events.push(event);
|
|
|
|
this.emit(event.type, event);
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2021-04-27 20:47:11 +02:00
|
|
|
batchStore(events: IEvent[]): Promise<void> {
|
2021-08-12 15:04:37 +02:00
|
|
|
events.forEach((event) => {
|
2021-03-12 11:08:10 +01:00
|
|
|
this.events.push(event);
|
|
|
|
this.emit(event.type, event);
|
|
|
|
});
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
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 getEventsFilterByType(type: string): Promise<IEvent[]> {
|
|
|
|
return this.events.filter((e) => e.type === type);
|
2021-01-19 10:42:45 +01:00
|
|
|
}
|
2021-09-20 12:13:38 +02:00
|
|
|
|
|
|
|
async getEventsFilterByProject(project: string): Promise<IEvent[]> {
|
|
|
|
return this.events.filter((e) => e.project === project);
|
|
|
|
}
|
2021-01-19 10:42:45 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 20:47:11 +02:00
|
|
|
module.exports = FakeEventStore;
|
|
|
|
export default FakeEventStore;
|