From eec2bfd2e6a8b9e6337f906928061076675eb4b8 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Wed, 21 Aug 2024 14:22:38 +0200 Subject: [PATCH] fix: enable disabled strategies keeps settings (#7952) --- .../feature-toggle/feature-toggle-service.ts | 2 +- .../tests/feature-toggle-service.e2e.test.ts | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/lib/features/feature-toggle/feature-toggle-service.ts b/src/lib/features/feature-toggle/feature-toggle-service.ts index 08a4fa3ad87f..5a5689dc5851 100644 --- a/src/lib/features/feature-toggle/feature-toggle-service.ts +++ b/src/lib/features/feature-toggle/feature-toggle-service.ts @@ -1886,7 +1886,7 @@ class FeatureToggleService { strategies.map((strategy) => this.updateStrategy( strategy.id, - { disabled: false }, + { ...strategy, disabled: false }, { environment, projectId: project, diff --git a/src/lib/features/feature-toggle/tests/feature-toggle-service.e2e.test.ts b/src/lib/features/feature-toggle/tests/feature-toggle-service.e2e.test.ts index 92dce170d034..e9cec58a41a4 100644 --- a/src/lib/features/feature-toggle/tests/feature-toggle-service.e2e.test.ts +++ b/src/lib/features/feature-toggle/tests/feature-toggle-service.e2e.test.ts @@ -744,3 +744,51 @@ test('Should return "default" for stickiness when creating a flexibleRollout str strategies: [{ parameters: { stickiness: 'default' } }], }); }); + +test('Should enable disabled strategies on feature environment enabled', async () => { + const flagName = 'enableThisFlag'; + const project = 'default'; + const environment = 'default'; + const shouldActivateDisabledStrategies = true; + await service.createFeatureToggle( + project, + { + name: flagName, + }, + TEST_AUDIT_USER, + ); + const config: Omit = { + name: 'default', + constraints: [ + { contextName: 'userId', operator: 'IN', values: ['1', '1'] }, + ], + parameters: { param: 'a' }, + variants: [ + { + name: 'a', + weight: 100, + weightType: 'variable', + stickiness: 'random', + }, + ], + disabled: true, + }; + const createdConfig = await service.createStrategy( + config, + { projectId: project, featureName: flagName, environment }, + TEST_AUDIT_USER, + ); + + await service.updateEnabled( + project, + flagName, + environment, + true, + TEST_AUDIT_USER, + { email: 'test@example.com' } as User, + shouldActivateDisabledStrategies, + ); + + const strategy = await service.getStrategy(createdConfig.id); + expect(strategy).toMatchObject({ ...config, disabled: false }); +});