2021-08-12 15:04:37 +02:00
|
|
|
import {
|
|
|
|
FeatureEnvironmentKey,
|
|
|
|
IFeatureEnvironmentStore,
|
|
|
|
} from '../../lib/types/stores/feature-environment-store';
|
2022-11-21 10:37:16 +01:00
|
|
|
import { IFeatureEnvironment, IVariant } from '../../lib/types/model';
|
2021-08-12 15:04:37 +02:00
|
|
|
import NotFoundError from '../../lib/error/notfound-error';
|
|
|
|
|
|
|
|
export default class FakeFeatureEnvironmentStore
|
|
|
|
implements IFeatureEnvironmentStore
|
|
|
|
{
|
|
|
|
featureEnvironments: IFeatureEnvironment[] = [];
|
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
async addEnvironmentToFeature(
|
2021-08-12 15:04:37 +02:00
|
|
|
featureName: string,
|
|
|
|
environment: string,
|
|
|
|
enabled: boolean,
|
|
|
|
): Promise<void> {
|
|
|
|
this.featureEnvironments.push({ environment, enabled, featureName });
|
|
|
|
}
|
|
|
|
|
2022-11-21 10:37:16 +01:00
|
|
|
async addVariantsToFeatureEnvironment(
|
|
|
|
featureName: string,
|
|
|
|
environment: string,
|
|
|
|
variants: IVariant[],
|
|
|
|
): Promise<void> {
|
|
|
|
this.featureEnvironments
|
|
|
|
.filter(
|
|
|
|
(fe) =>
|
|
|
|
fe.featureName === featureName &&
|
|
|
|
fe.environment === environment,
|
|
|
|
)
|
|
|
|
.map((fe) => (fe.variants = variants));
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
async delete(key: FeatureEnvironmentKey): Promise<void> {
|
|
|
|
this.featureEnvironments.splice(
|
|
|
|
this.featureEnvironments.findIndex(
|
|
|
|
(fE) =>
|
|
|
|
fE.environment === key.environment &&
|
|
|
|
fE.featureName === key.featureName,
|
|
|
|
),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteAll(): Promise<void> {
|
|
|
|
this.featureEnvironments = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
destroy(): void {}
|
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
async disconnectFeatures(
|
2021-08-12 15:04:37 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environment: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
project: string,
|
|
|
|
): Promise<void> {
|
|
|
|
return Promise.resolve(undefined);
|
|
|
|
}
|
|
|
|
|
|
|
|
async exists(key: FeatureEnvironmentKey): Promise<boolean> {
|
|
|
|
return this.featureEnvironments.some(
|
|
|
|
(fE) =>
|
|
|
|
fE.featureName === key.featureName &&
|
|
|
|
fE.environment === key.environment,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async featureHasEnvironment(
|
|
|
|
environment: string,
|
|
|
|
featureName: string,
|
|
|
|
): Promise<boolean> {
|
|
|
|
return this.exists({ environment, featureName });
|
|
|
|
}
|
|
|
|
|
|
|
|
async get(key: FeatureEnvironmentKey): Promise<IFeatureEnvironment> {
|
|
|
|
const featureEnvironment = this.featureEnvironments.find(
|
|
|
|
(fE) =>
|
|
|
|
fE.environment === key.environment &&
|
|
|
|
fE.featureName === key.featureName,
|
|
|
|
);
|
|
|
|
if (featureEnvironment) {
|
|
|
|
return featureEnvironment;
|
|
|
|
}
|
|
|
|
throw new NotFoundError(
|
|
|
|
`Could not find environment ${key.environment} for feature: ${key.featureName}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAll(): Promise<IFeatureEnvironment[]> {
|
|
|
|
return this.featureEnvironments;
|
|
|
|
}
|
|
|
|
|
|
|
|
getEnvironmentMetaData(
|
|
|
|
environment: string,
|
|
|
|
featureName: string,
|
|
|
|
): Promise<IFeatureEnvironment> {
|
|
|
|
return this.get({ environment, featureName });
|
|
|
|
}
|
|
|
|
|
|
|
|
async isEnvironmentEnabled(
|
|
|
|
featureName: string,
|
|
|
|
environment: string,
|
|
|
|
): Promise<boolean> {
|
|
|
|
try {
|
|
|
|
const fE = await this.get({ featureName, environment });
|
|
|
|
return fE.enabled;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeEnvironmentForFeature(
|
|
|
|
featureName: string,
|
|
|
|
environment: string,
|
|
|
|
): Promise<void> {
|
|
|
|
return this.delete({ featureName, environment });
|
|
|
|
}
|
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
async setEnvironmentEnabledStatus(
|
2021-08-12 15:04:37 +02:00
|
|
|
environment: string,
|
|
|
|
featureName: string,
|
|
|
|
enabled: boolean,
|
2021-10-21 22:33:50 +02:00
|
|
|
): Promise<number> {
|
2021-08-12 15:04:37 +02:00
|
|
|
const fE = await this.get({ environment, featureName });
|
2021-10-21 22:33:50 +02:00
|
|
|
if (fE.enabled !== enabled) {
|
|
|
|
fE.enabled = enabled;
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-08-12 15:04:37 +02:00
|
|
|
}
|
2021-09-13 10:23:57 +02:00
|
|
|
|
|
|
|
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> {
|
2022-11-17 14:05:57 +01:00
|
|
|
return Promise.resolve(undefined);
|
2021-09-13 10:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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'));
|
|
|
|
}
|
|
|
|
|
|
|
|
async disconnectProject(
|
|
|
|
// 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 connectFeatureToEnvironmentsForProject(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
featureName: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
projectId: string,
|
|
|
|
): Promise<void> {
|
2022-10-19 14:05:07 +02:00
|
|
|
return Promise.resolve();
|
2021-09-13 10:23:57 +02:00
|
|
|
}
|
2021-10-06 09:25:34 +02:00
|
|
|
|
|
|
|
disableEnvironmentIfNoStrategies(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
featureName: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environment: string,
|
|
|
|
): Promise<void> {
|
|
|
|
return Promise.reject(new Error('Not implemented'));
|
|
|
|
}
|
2022-10-28 11:27:11 +02:00
|
|
|
|
|
|
|
copyEnvironmentFeaturesByProjects(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
sourceEnvironment: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
destinationEnvironment: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
projects: string[],
|
|
|
|
): Promise<void> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
|
|
|
|
|
|
|
cloneStrategies(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
sourceEnvironment: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
destinationEnvironment: string,
|
|
|
|
): Promise<void> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
2022-11-21 10:37:16 +01:00
|
|
|
|
|
|
|
async addFeatureEnvironment(
|
|
|
|
featureEnvironment: IFeatureEnvironment,
|
|
|
|
): Promise<void> {
|
|
|
|
this.featureEnvironments.push(featureEnvironment);
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
getEnvironmentsForFeature(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
featureName: string,
|
|
|
|
): Promise<IFeatureEnvironment[]> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
|
|
|
|
|
|
|
clonePreviousVariants(
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
environment: string,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
project: string,
|
|
|
|
): Promise<void> {
|
|
|
|
throw new Error('Method not implemented.');
|
|
|
|
}
|
2021-08-12 15:04:37 +02:00
|
|
|
}
|