mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Fix/feature strategies needs project update (#1040)
* Make sure feature_strategies follow feature to new project
This commit is contained in:
parent
3f02e9c070
commit
26407cc02e
@ -409,6 +409,15 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
|
||||
.where({ project_name: projectId, environment })
|
||||
.del();
|
||||
}
|
||||
|
||||
async setProjectForStrategiesBelongingToFeature(
|
||||
featureName: string,
|
||||
newProjectId: string,
|
||||
): Promise<void> {
|
||||
await this.db(T.featureStrategies)
|
||||
.where({ feature_name: featureName })
|
||||
.update({ project_name: newProjectId });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FeatureStrategiesStore;
|
||||
|
@ -785,6 +785,16 @@ class FeatureToggleServiceV2 {
|
||||
async getProjectId(name: string): Promise<string> {
|
||||
return this.featureToggleStore.getProjectId(name);
|
||||
}
|
||||
|
||||
async updateFeatureStrategyProject(
|
||||
featureName: string,
|
||||
newProjectId: string,
|
||||
): Promise<void> {
|
||||
await this.featureStrategiesStore.setProjectForStrategiesBelongingToFeature(
|
||||
featureName,
|
||||
newProjectId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FeatureToggleServiceV2;
|
||||
|
@ -195,6 +195,10 @@ export default class ProjectService {
|
||||
user.username,
|
||||
FEATURE_PROJECT_CHANGE,
|
||||
);
|
||||
await this.featureToggleService.updateFeatureStrategyProject(
|
||||
featureName,
|
||||
newProjectId,
|
||||
);
|
||||
|
||||
return updatedFeature;
|
||||
}
|
||||
|
@ -46,4 +46,9 @@ export interface IFeatureStrategiesStore
|
||||
projectId: String,
|
||||
environment: String,
|
||||
): Promise<void>;
|
||||
|
||||
setProjectForStrategiesBelongingToFeature(
|
||||
featureName: string,
|
||||
newProjectId: string,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
72
src/test/e2e/stores/feature-strategies-store.e2e.test.ts
Normal file
72
src/test/e2e/stores/feature-strategies-store.e2e.test.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { IFeatureStrategiesStore } from 'lib/types/stores/feature-strategies-store';
|
||||
import { IFeatureToggleStore } from 'lib/types/stores/feature-toggle-store';
|
||||
import dbInit from '../helpers/database-init';
|
||||
import getLogger from '../../fixtures/no-logger';
|
||||
|
||||
let stores;
|
||||
let db;
|
||||
let featureStrategiesStore: IFeatureStrategiesStore;
|
||||
let featureToggleStore: IFeatureToggleStore;
|
||||
|
||||
const featureName = 'test-strategies-move-project';
|
||||
|
||||
beforeAll(async () => {
|
||||
db = await dbInit('feature_strategies_store_serial', getLogger);
|
||||
stores = db.stores;
|
||||
featureStrategiesStore = stores.featureStrategiesStore;
|
||||
featureToggleStore = stores.featureToggleStore;
|
||||
await featureToggleStore.create('default', { name: featureName });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await db.destroy();
|
||||
});
|
||||
|
||||
test('Can successfully update project for all strategies belonging to feature', async () => {
|
||||
const newProjectId = 'different-project';
|
||||
const oldProjectId = 'default';
|
||||
const environment = 'default';
|
||||
await featureStrategiesStore.createStrategyFeatureEnv({
|
||||
strategyName: 'default',
|
||||
projectId: oldProjectId,
|
||||
environment,
|
||||
featureName,
|
||||
constraints: [],
|
||||
parameters: {},
|
||||
sortOrder: 15,
|
||||
});
|
||||
await featureStrategiesStore.createStrategyFeatureEnv({
|
||||
strategyName: 'default',
|
||||
projectId: oldProjectId,
|
||||
environment,
|
||||
featureName,
|
||||
constraints: [],
|
||||
parameters: {},
|
||||
sortOrder: 20,
|
||||
});
|
||||
const strats = await featureStrategiesStore.getStrategiesForFeatureEnv(
|
||||
oldProjectId,
|
||||
featureName,
|
||||
environment,
|
||||
);
|
||||
expect(strats).toHaveLength(2);
|
||||
await featureStrategiesStore.setProjectForStrategiesBelongingToFeature(
|
||||
featureName,
|
||||
newProjectId,
|
||||
);
|
||||
const newProjectStrats =
|
||||
await featureStrategiesStore.getStrategiesForFeatureEnv(
|
||||
newProjectId,
|
||||
featureName,
|
||||
environment,
|
||||
);
|
||||
expect(newProjectStrats).toHaveLength(2);
|
||||
|
||||
const oldProjectStrats =
|
||||
await featureStrategiesStore.getStrategiesForFeatureEnv(
|
||||
oldProjectId,
|
||||
featureName,
|
||||
environment,
|
||||
);
|
||||
return expect(oldProjectStrats).toHaveLength(0);
|
||||
});
|
@ -250,6 +250,19 @@ export default class FakeFeatureStrategiesStore
|
||||
return Promise.resolve(enabled);
|
||||
}
|
||||
|
||||
async setProjectForStrategiesBelongingToFeature(
|
||||
featureName: string,
|
||||
newProjectId: string,
|
||||
): Promise<void> {
|
||||
this.featureStrategies = this.featureStrategies.map((f) => {
|
||||
if (f.featureName === featureName) {
|
||||
f.projectId = newProjectId;
|
||||
}
|
||||
return f;
|
||||
});
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
async setEnvironmentEnabledStatus(
|
||||
environment: string,
|
||||
featureName: string,
|
||||
|
Loading…
Reference in New Issue
Block a user