2021-07-07 10:46:50 +02:00
|
|
|
import { IEnvironment } from '../../lib/types/model';
|
|
|
|
import NotFoundError from '../../lib/error/notfound-error';
|
2021-08-12 15:04:37 +02:00
|
|
|
import { IEnvironmentStore } from '../../lib/types/stores/environment-store';
|
2021-07-07 10:46:50 +02:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
export default class FakeEnvironmentStore implements IEnvironmentStore {
|
2021-07-07 10:46:50 +02:00
|
|
|
environments: IEnvironment[] = [];
|
|
|
|
|
|
|
|
async getAll(): Promise<IEnvironment[]> {
|
2021-08-12 15:04:37 +02:00
|
|
|
return this.environments;
|
2021-07-07 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
async exists(name: string): Promise<boolean> {
|
|
|
|
return this.environments.some((e) => e.name === name);
|
2021-07-07 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async getByName(name: string): Promise<IEnvironment> {
|
2021-08-12 15:04:37 +02:00
|
|
|
const env = this.environments.find((e) => e.name === name);
|
2021-07-07 10:46:50 +02:00
|
|
|
if (env) {
|
|
|
|
return Promise.resolve(env);
|
|
|
|
}
|
|
|
|
return Promise.reject(
|
|
|
|
new NotFoundError(`Could not find environment with name ${name}`),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async upsert(env: IEnvironment): Promise<IEnvironment> {
|
2021-08-12 15:04:37 +02:00
|
|
|
this.environments = this.environments.filter(
|
|
|
|
(e) => e.name !== env.name,
|
|
|
|
);
|
2021-07-07 10:46:50 +02:00
|
|
|
this.environments.push(env);
|
|
|
|
return Promise.resolve(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete(name: string): Promise<void> {
|
2021-08-12 15:04:37 +02:00
|
|
|
this.environments = this.environments.filter((e) => e.name !== name);
|
2021-07-07 10:46:50 +02:00
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
async deleteAll(): Promise<void> {
|
|
|
|
this.environments = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy(): void {}
|
|
|
|
|
|
|
|
async get(key: string): Promise<IEnvironment> {
|
|
|
|
return this.environments.find((e) => e.name === key);
|
|
|
|
}
|
2021-07-07 10:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = FakeEnvironmentStore;
|