diff --git a/src/lib/services/feature-toggle-service.ts b/src/lib/services/feature-toggle-service.ts index 5b905bffee..9971747aa3 100644 --- a/src/lib/services/feature-toggle-service.ts +++ b/src/lib/services/feature-toggle-service.ts @@ -801,9 +801,7 @@ class FeatureToggleService { featureName: newFeatureName, environment: e.name, }; - return this.createStrategy(s, context, userName).then((s2) => - this.segmentService.cloneStrategySegments(s.id, s2.id), - ); + return this.createStrategy(s, context, userName); }), ); diff --git a/src/test/e2e/services/feature-toggle-service-v2.e2e.test.ts b/src/test/e2e/services/feature-toggle-service-v2.e2e.test.ts index 619e46bf57..050443539d 100644 --- a/src/test/e2e/services/feature-toggle-service-v2.e2e.test.ts +++ b/src/test/e2e/services/feature-toggle-service-v2.e2e.test.ts @@ -311,3 +311,53 @@ test('cloning a feature toggle copies variant environments correctly', async () expect(defaultEnv.variants).toHaveLength(0); expect(newEnv.variants).toHaveLength(1); }); + +test('Cloning a feature toggle also clones segments correctly', async () => { + const featureName = 'ToggleWithSegments'; + const clonedFeatureName = 'AWholeNewFeatureToggle'; + + let segment = await segmentService.create( + { + name: 'SomeSegment', + constraints: mockConstraints(), + }, + { + email: 'test@example.com', + }, + ); + + await service.createFeatureToggle( + 'default', + { + name: featureName, + }, + 'test-user', + ); + + const config: Omit = { + name: 'default', + constraints: [], + parameters: {}, + segments: [segment.id], + }; + + await service.createStrategy( + config, + { projectId: 'default', featureName, environment: DEFAULT_ENV }, + 'test-user', + ); + + await service.cloneFeatureToggle( + featureName, + 'default', + clonedFeatureName, + true, + 'test-user', + ); + + let feature = await service.getFeature(clonedFeatureName); + expect( + feature.environments.find((x) => x.name === 'default').strategies[0] + .segments, + ).toHaveLength(1); +});