1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: resolve an issue where cloning a feature toggle with a segment (#2511)

fix an issue where cloning a feature toggle with a strategy with segments would raise an error but still clone successfully
This commit is contained in:
Simon Hornby 2022-11-23 15:39:09 +02:00 committed by GitHub
parent 9fee0bb264
commit 0897180af5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 3 deletions

View File

@ -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);
}),
);

View File

@ -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<FeatureStrategySchema, 'id'> = {
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);
});