diff --git a/src/lib/services/feature-toggle-service-v2.ts b/src/lib/services/feature-toggle-service-v2.ts index 484c946b4f..b7abcfb128 100644 --- a/src/lib/services/feature-toggle-service-v2.ts +++ b/src/lib/services/feature-toggle-service-v2.ts @@ -13,6 +13,7 @@ import { FEATURE_ENVIRONMENT_DISABLED, FEATURE_ENVIRONMENT_ENABLED, FEATURE_METADATA_UPDATED, + FEATURE_PROJECT_CHANGE, FEATURE_REVIVED, FEATURE_STALE_OFF, FEATURE_STALE_ON, @@ -723,34 +724,30 @@ class FeatureToggleServiceV2 { return { ...legacyFeature, enabled, strategies }; } - // @deprecated - // TODO: move to projectService - async updateField( + async changeProject( featureName: string, - field: string, - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types - value: any, + newProject: string, userName: string, - event: string, - ): Promise { + ): Promise { const feature = await this.featureToggleStore.get(featureName); - feature[field] = value; - await this.featureToggleStore.update(feature.project, feature); + const oldProject = feature.project; + feature.project = newProject; + await this.featureToggleStore.update(newProject, feature); + const tags = await this.featureTagStore.getAllTagsForFeature( featureName, ); - - // Workaround to support pre 4.1 format - const data = await this.getFeatureToggleLegacy(featureName); - await this.eventStore.store({ - type: event, + type: FEATURE_PROJECT_CHANGE, createdBy: userName, - data, - project: data.project, + data: { + name: feature.name, + oldProject, + newProject, + }, + project: newProject, tags, }); - return feature; } async getArchivedFeatures(): Promise { diff --git a/src/lib/services/project-service.ts b/src/lib/services/project-service.ts index fd9bcc8fb8..bce88e7837 100644 --- a/src/lib/services/project-service.ts +++ b/src/lib/services/project-service.ts @@ -6,7 +6,6 @@ import { nameType } from '../routes/util'; import { projectSchema } from './project-schema'; import NotFoundError from '../error/notfound-error'; import { - FEATURE_PROJECT_CHANGE, PROJECT_CREATED, PROJECT_DELETED, PROJECT_UPDATED, @@ -222,12 +221,10 @@ export default class ProjectService { if (!isCompatibleWithTargetProject) { throw new IncompatibleProjectError(newProjectId); } - const updatedFeature = await this.featureToggleService.updateField( + const updatedFeature = await this.featureToggleService.changeProject( featureName, - 'project', newProjectId, user.username, - FEATURE_PROJECT_CHANGE, ); await this.featureToggleService.updateFeatureStrategyProject( featureName, diff --git a/src/test/e2e/services/project-service.e2e.test.ts b/src/test/e2e/services/project-service.e2e.test.ts index 0e6f26fe4f..e313f2ebcb 100644 --- a/src/test/e2e/services/project-service.e2e.test.ts +++ b/src/test/e2e/services/project-service.e2e.test.ts @@ -17,7 +17,7 @@ let db: ITestDb; let projectService; let accessService; -let featureToggleService; +let featureToggleService: FeatureToggleServiceV2; let user; beforeAll(async () => { @@ -511,13 +511,15 @@ test('should change project when checks pass', async () => { await projectService.createProject(projectDestination, user); await featureToggleService.createFeatureToggle(project.id, toggle, user); - const updatedFeature = await projectService.changeProject( + await projectService.changeProject( projectDestination.id, toggle.name, user, project.id, ); + const updatedFeature = await featureToggleService.getFeature(toggle.name); + expect(updatedFeature.project).toBe(projectDestination.id); });