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-09-24 13:55:00 +02:00
|
|
|
importEnvironments(envs: IEnvironment[]): Promise<IEnvironment[]> {
|
|
|
|
this.environments = envs;
|
|
|
|
return Promise.resolve(envs);
|
|
|
|
}
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
environments: IEnvironment[] = [];
|
|
|
|
|
2022-03-11 14:52:13 +01:00
|
|
|
disable(environments: IEnvironment[]): Promise<void> {
|
2022-03-11 10:16:58 +01:00
|
|
|
for (let env of this.environments) {
|
2022-03-11 14:52:13 +01:00
|
|
|
if (environments.map((e) => e.name).includes(env.name))
|
|
|
|
env.enabled = false;
|
2022-03-11 10:16:58 +01:00
|
|
|
}
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2022-03-11 14:52:13 +01:00
|
|
|
enable(environments: IEnvironment[]): Promise<void> {
|
2022-03-11 10:16:58 +01:00
|
|
|
for (let env of this.environments) {
|
2022-03-11 14:52:13 +01:00
|
|
|
if (environments.map((e) => e.name).includes(env.name))
|
|
|
|
env.enabled = true;
|
2022-03-11 10:16:58 +01:00
|
|
|
}
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2022-09-06 13:24:13 +02:00
|
|
|
count(): Promise<number> {
|
|
|
|
return Promise.resolve(this.environments.length);
|
|
|
|
}
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
async getAll(): Promise<IEnvironment[]> {
|
2022-09-06 13:24:13 +02:00
|
|
|
return Promise.resolve(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}`),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-13 15:57:38 +02:00
|
|
|
async create(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);
|
|
|
|
}
|
|
|
|
|
2021-09-13 15:57:38 +02:00
|
|
|
async update(
|
2021-09-29 10:23:43 +02:00
|
|
|
env: Pick<IEnvironment, 'type' | 'protected'>,
|
2021-09-13 15:57:38 +02:00
|
|
|
name: string,
|
|
|
|
): Promise<IEnvironment> {
|
|
|
|
const found = this.environments.find(
|
|
|
|
(en: IEnvironment) => en.name === name,
|
|
|
|
);
|
|
|
|
const idx = this.environments.findIndex(
|
|
|
|
(en: IEnvironment) => en.name === name,
|
|
|
|
);
|
|
|
|
const updated = { ...found, env };
|
|
|
|
|
|
|
|
this.environments[idx] = updated;
|
|
|
|
return Promise.resolve(updated);
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateSortOrder(id: string, value: number): Promise<void> {
|
|
|
|
const environment = this.environments.find(
|
|
|
|
(env: IEnvironment) => env.name === id,
|
|
|
|
);
|
|
|
|
environment.sortOrder = value;
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateProperty(
|
|
|
|
id: string,
|
|
|
|
field: string,
|
|
|
|
value: string | number,
|
|
|
|
): Promise<void> {
|
|
|
|
const environment = this.environments.find(
|
|
|
|
(env: IEnvironment) => env.name === id,
|
|
|
|
);
|
|
|
|
environment[field] = value;
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
async connectProject(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environment: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
projectId: string,
|
|
|
|
): Promise<void> {
|
|
|
|
return Promise.reject(new Error('Not implemented'));
|
|
|
|
}
|
|
|
|
|
|
|
|
async connectFeatures(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environment: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
projectId: string,
|
|
|
|
): Promise<void> {
|
|
|
|
return Promise.reject(new Error('Not implemented'));
|
|
|
|
}
|
|
|
|
|
2021-07-07 10:46:50 +02:00
|
|
|
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;
|