mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
fix: playground parent deps check (#7384)
This commit is contained in:
parent
50316a2f23
commit
3cc0dfe35a
@ -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-parent');
|
||||||
await createFeatureToggle('test-child');
|
await createFeatureToggle('test-child');
|
||||||
await enableToggle('test-child');
|
await enableToggle('test-child');
|
||||||
@ -126,6 +126,35 @@ test('advanced playground evaluation with parent dependency', async () => {
|
|||||||
expect(parent.isEnabled).toBe(false);
|
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 () => {
|
test('advanced playground evaluation happy path', async () => {
|
||||||
await createFeatureToggleWithStrategy('test-playground-feature');
|
await createFeatureToggleWithStrategy('test-playground-feature');
|
||||||
await enableToggle('test-playground-feature');
|
await enableToggle('test-playground-feature');
|
||||||
|
@ -77,9 +77,6 @@ export default class UnleashClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parent.enabled !== false) {
|
if (parent.enabled !== false) {
|
||||||
if (!parentToggle.enabled) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (parent.variants?.length) {
|
if (parent.variants?.length) {
|
||||||
return parent.variants.includes(
|
return parent.variants.includes(
|
||||||
this.getVariant(parent.feature, context).name,
|
this.getVariant(parent.feature, context).name,
|
||||||
@ -91,12 +88,9 @@ export default class UnleashClient {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return !(
|
||||||
!parentToggle.enabled &&
|
this.isEnabled(parent.feature, context, () => false).result ===
|
||||||
!(
|
true
|
||||||
this.isEnabled(parent.feature, context, () => false)
|
|
||||||
.result === true
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import type { Db } from '../../../lib/db/db';
|
|||||||
import type { IContextFieldDto } from '../../../lib/types/stores/context-field-store';
|
import type { IContextFieldDto } from '../../../lib/types/stores/context-field-store';
|
||||||
import { DEFAULT_ENV } from '../../../lib/util';
|
import { DEFAULT_ENV } from '../../../lib/util';
|
||||||
import type {
|
import type {
|
||||||
|
CreateDependentFeatureSchema,
|
||||||
CreateFeatureSchema,
|
CreateFeatureSchema,
|
||||||
CreateFeatureStrategySchema,
|
CreateFeatureStrategySchema,
|
||||||
ImportTogglesSchema,
|
ImportTogglesSchema,
|
||||||
@ -102,7 +103,10 @@ export interface IUnleashHttpAPI {
|
|||||||
expectedResponseCode?: number,
|
expectedResponseCode?: number,
|
||||||
): supertest.Test;
|
): supertest.Test;
|
||||||
|
|
||||||
addDependency(child: string, parent: string): supertest.Test;
|
addDependency(
|
||||||
|
child: string,
|
||||||
|
parent: string | CreateDependentFeatureSchema,
|
||||||
|
): supertest.Test;
|
||||||
|
|
||||||
addTag(
|
addTag(
|
||||||
feature: string,
|
feature: string,
|
||||||
@ -224,7 +228,7 @@ function httpApis(
|
|||||||
|
|
||||||
addDependency(
|
addDependency(
|
||||||
child: string,
|
child: string,
|
||||||
parent: string,
|
parent: string | CreateDependentFeatureSchema,
|
||||||
project = DEFAULT_PROJECT,
|
project = DEFAULT_PROJECT,
|
||||||
expectedResponseCode: number = 200,
|
expectedResponseCode: number = 200,
|
||||||
): supertest.Test {
|
): supertest.Test {
|
||||||
@ -232,7 +236,7 @@ function httpApis(
|
|||||||
.post(
|
.post(
|
||||||
`/api/admin/projects/${project}/features/${child}/dependencies`,
|
`/api/admin/projects/${project}/features/${child}/dependencies`,
|
||||||
)
|
)
|
||||||
.send({ feature: parent })
|
.send(typeof parent === 'string' ? { feature: parent } : parent)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(expectedResponseCode);
|
.expect(expectedResponseCode);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user