From afa34867c1eb8814e1ad829ec63fe8407924e3af Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Mon, 5 Aug 2024 10:39:21 +0200 Subject: [PATCH] fix: playground parent disabled with strategy (#7744) --- .../features/playground/advanced-playground.test.ts | 11 +++++++++++ .../features/playground/feature-evaluator/client.ts | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/lib/features/playground/advanced-playground.test.ts b/src/lib/features/playground/advanced-playground.test.ts index ba01856918..9824e46cc9 100644 --- a/src/lib/features/playground/advanced-playground.test.ts +++ b/src/lib/features/playground/advanced-playground.test.ts @@ -59,6 +59,13 @@ const enableToggle = (featureName: string) => ) .send({}) .expect(200); +const disableToggle = (featureName: string) => + app.request + .post( + `/api/admin/projects/default/features/${featureName}/environments/default/off`, + ) + .send({}) + .expect(200); afterAll(async () => { await app.destroy(); @@ -99,6 +106,8 @@ test('advanced playground evaluation with unsatisfied parent dependency', async await createFeatureToggle('test-parent'); await createFeatureToggle('test-child'); await enableToggle('test-child'); + await enableToggle('test-parent'); + await disableToggle('test-parent'); await app.addDependency('test-child', 'test-parent'); const { body: result } = await app.request @@ -116,6 +125,7 @@ test('advanced playground evaluation with unsatisfied parent dependency', async // child is disabled because of the parent expect(child.hasUnsatisfiedDependency).toBe(true); expect(child.isEnabled).toBe(false); + expect(child.strategies.data.length).toBe(1); expect(child.isEnabledInCurrentEnvironment).toBe(true); expect(child.variant).toEqual({ name: 'disabled', @@ -124,6 +134,7 @@ test('advanced playground evaluation with unsatisfied parent dependency', async }); expect(parent.hasUnsatisfiedDependency).toBe(false); expect(parent.isEnabled).toBe(false); + expect(parent.strategies.data.length).toBe(1); }); test('advanced playground evaluation with satisfied disabled parent dependency', async () => { diff --git a/src/lib/features/playground/feature-evaluator/client.ts b/src/lib/features/playground/feature-evaluator/client.ts index 177dc81667..85613e9e4d 100644 --- a/src/lib/features/playground/feature-evaluator/client.ts +++ b/src/lib/features/playground/feature-evaluator/client.ts @@ -75,6 +75,9 @@ export default class UnleashClient { if (parentToggle.dependencies?.length) { return false; } + if (Boolean(parent.enabled) !== Boolean(parentToggle.enabled)) { + return false; + } if (parent.enabled !== false) { if (parent.variants?.length) {