1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/test/fixtures/fake-client-applications-store.ts
olav ee35c7ad74
refactor: replace ts-ignore with ts-expect-error (#1675)
* refactor: replace ts-ignore with ts-expect-error

* refactor: remove unused ts-expect-errors
2022-06-07 11:49:17 +02:00

82 lines
2.2 KiB
TypeScript

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<IClientApplication>[]): Promise<void> {
// @ts-expect-error
details.forEach((d) => this.apps.push(d));
}
async delete(key: string): Promise<void> {
this.apps.splice(
this.apps.findIndex((a) => a.appName === key),
1,
);
}
async deleteAll(): Promise<void> {
this.apps = [];
}
async deleteApplication(appName: string): Promise<void> {
return this.delete(appName);
}
destroy(): void {}
async exists(key: string): Promise<boolean> {
return this.apps.some((a) => a.appName === key);
}
async get(key: string): Promise<IClientApplication> {
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<IClientApplication[]> {
return this.apps;
}
async getApplication(appName: string): Promise<IClientApplication> {
return this.get(appName);
}
async getAppsForStrategy(
query: IApplicationQuery,
): Promise<IClientApplication[]> {
if (query.strategyName) {
return this.apps.filter((a) =>
a.strategies.includes(query.strategyName),
);
}
return this.apps;
}
async getUnannounced(): Promise<IClientApplication[]> {
return this.apps.filter((a) => !a.announced);
}
async setUnannouncedToAnnounced(): Promise<IClientApplication[]> {
this.apps = this.apps.map((a) => ({ ...a, announced: true }));
return this.apps;
}
async upsert(details: Partial<IClientApplication>): Promise<void> {
await this.delete(details.appName);
return this.bulkUpsert([details]);
}
}