From 3cc0dfe35af0791b7674c6c9725afd7f85353e13 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Thu, 13 Jun 2024 10:36:44 +0200 Subject: [PATCH] fix: playground parent deps check (#7384) --- .../playground/advanced-playground.test.ts | 31 ++++++++++++++++++- .../playground/feature-evaluator/client.ts | 12 ++----- src/test/e2e/helpers/test-helper.ts | 10 ++++-- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/lib/features/playground/advanced-playground.test.ts b/src/lib/features/playground/advanced-playground.test.ts index 4005829ac1..ba01856918 100644 --- a/src/lib/features/playground/advanced-playground.test.ts +++ b/src/lib/features/playground/advanced-playground.test.ts @@ -95,7 +95,7 @@ test('advanced playground evaluation with no toggles', async () => { }); }); -test('advanced playground evaluation with parent dependency', async () => { +test('advanced playground evaluation with unsatisfied parent dependency', async () => { await createFeatureToggle('test-parent'); await createFeatureToggle('test-child'); await enableToggle('test-child'); @@ -126,6 +126,35 @@ test('advanced playground evaluation with parent dependency', async () => { expect(parent.isEnabled).toBe(false); }); +test('advanced playground evaluation with satisfied disabled parent dependency', async () => { + await createFeatureToggle('test-parent'); + await createFeatureToggle('test-child'); + await enableToggle('test-child'); + await app.addDependency('test-child', { + feature: 'test-parent', + enabled: false, + variants: [], + }); + + const { body: result } = await app.request + .post('/api/admin/playground/advanced') + .send({ + environments: ['default'], + projects: ['default'], + context: { appName: 'test' }, + }) + .set('Content-Type', 'application/json') + .expect(200); + + const child = result.features[0].environments.default[0]; + const parent = result.features[1].environments.default[0]; + + expect(child.hasUnsatisfiedDependency).toBe(false); + expect(child.isEnabled).toBe(true); + expect(parent.hasUnsatisfiedDependency).toBe(false); + expect(parent.isEnabled).toBe(false); +}); + test('advanced playground evaluation happy path', async () => { await createFeatureToggleWithStrategy('test-playground-feature'); await enableToggle('test-playground-feature'); diff --git a/src/lib/features/playground/feature-evaluator/client.ts b/src/lib/features/playground/feature-evaluator/client.ts index 2d09cc6dd8..177dc81667 100644 --- a/src/lib/features/playground/feature-evaluator/client.ts +++ b/src/lib/features/playground/feature-evaluator/client.ts @@ -77,9 +77,6 @@ export default class UnleashClient { } if (parent.enabled !== false) { - if (!parentToggle.enabled) { - return false; - } if (parent.variants?.length) { return parent.variants.includes( this.getVariant(parent.feature, context).name, @@ -91,12 +88,9 @@ export default class UnleashClient { ); } - return ( - !parentToggle.enabled && - !( - this.isEnabled(parent.feature, context, () => false) - .result === true - ) + return !( + this.isEnabled(parent.feature, context, () => false).result === + true ); }); } diff --git a/src/test/e2e/helpers/test-helper.ts b/src/test/e2e/helpers/test-helper.ts index a06f4a5b5c..bc4f81491b 100644 --- a/src/test/e2e/helpers/test-helper.ts +++ b/src/test/e2e/helpers/test-helper.ts @@ -15,6 +15,7 @@ import type { Db } from '../../../lib/db/db'; import type { IContextFieldDto } from '../../../lib/types/stores/context-field-store'; import { DEFAULT_ENV } from '../../../lib/util'; import type { + CreateDependentFeatureSchema, CreateFeatureSchema, CreateFeatureStrategySchema, ImportTogglesSchema, @@ -102,7 +103,10 @@ export interface IUnleashHttpAPI { expectedResponseCode?: number, ): supertest.Test; - addDependency(child: string, parent: string): supertest.Test; + addDependency( + child: string, + parent: string | CreateDependentFeatureSchema, + ): supertest.Test; addTag( feature: string, @@ -224,7 +228,7 @@ function httpApis( addDependency( child: string, - parent: string, + parent: string | CreateDependentFeatureSchema, project = DEFAULT_PROJECT, expectedResponseCode: number = 200, ): supertest.Test { @@ -232,7 +236,7 @@ function httpApis( .post( `/api/admin/projects/${project}/features/${child}/dependencies`, ) - .send({ feature: parent }) + .send(typeof parent === 'string' ? { feature: parent } : parent) .set('Content-Type', 'application/json') .expect(expectedResponseCode); },