import { IClientApplication, IClientApplicationsStore, } from '../../lib/types/stores/client-applications-store'; import NotFoundError from '../../lib/error/notfound-error'; import { IApplicationQuery } from '../../lib/types/query'; export default class FakeClientApplicationsStore implements IClientApplicationsStore { apps: IClientApplication[] = []; async bulkUpsert(details: Partial[]): Promise { // @ts-expect-error details.forEach((d) => this.apps.push(d)); } async delete(key: string): Promise { this.apps.splice( this.apps.findIndex((a) => a.appName === key), 1, ); } async deleteAll(): Promise { this.apps = []; } async deleteApplication(appName: string): Promise { return this.delete(appName); } destroy(): void {} async exists(key: string): Promise { return this.apps.some((a) => a.appName === key); } async get(key: string): Promise { const app = this.apps.find((a) => a.appName === key); if (app) { return app; } throw new NotFoundError( `Could not find application with appName: ${key}`, ); } async getAll(): Promise { return this.apps; } async getApplication(appName: string): Promise { return this.get(appName); } async getAppsForStrategy( query: IApplicationQuery, ): Promise { if (query.strategyName) { return this.apps.filter((a) => a.strategies.includes(query.strategyName), ); } return this.apps; } async getUnannounced(): Promise { return this.apps.filter((a) => !a.announced); } async setUnannouncedToAnnounced(): Promise { this.apps = this.apps.map((a) => ({ ...a, announced: true })); return this.apps; } async upsert(details: Partial): Promise { await this.delete(details.appName); return this.bulkUpsert([details]); } }