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-setting-store.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

import { ISettingStore } from '../../lib/types/stores/settings-store';
import NotFoundError from '../../lib/error/notfound-error';
export default class FakeSettingStore implements ISettingStore {
settings: Map<string, any> = new Map();
async delete(key: string): Promise<void> {
this.settings.delete(key);
}
async deleteAll(): Promise<void> {
this.settings = new Map();
}
destroy(): void {}
async exists(key: string): Promise<boolean> {
return this.settings.has(key);
}
async get(key: string): Promise<any> {
const setting = this.settings.get(key);
if (setting) {
return setting;
}
throw new NotFoundError(`Could not find setting with key ${key}`);
}
async getAll(): Promise<any[]> {
return Array.from(this.settings.values());
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
async insert(name: string, content: any): Promise<void> {
this.settings.set(name, content);
}
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
async updateRow(name: string, content: any): Promise<void> {
this.settings.set(name, content);
}
}