mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-18 00:19:49 +01:00
fix: Playground variants don't show correctly (#1829)
* Refactor: use the `ALL` constant for tests * Fix: context is not passed to `getVariant` call This commit fixes a bug wherein a toggle with variants would show as enabled but without variants. This was because the `getVariant` call didn't receive the provided context as an argument.
This commit is contained in:
parent
19b95b1bd9
commit
05c390e893
@ -58,7 +58,7 @@ export class PlaygroundService {
|
|||||||
projectId: await this.featureToggleService.getProjectId(
|
projectId: await this.featureToggleService.getProjectId(
|
||||||
feature.name,
|
feature.name,
|
||||||
),
|
),
|
||||||
variant: client.getVariant(feature.name),
|
variant: client.getVariant(feature.name, clientContext),
|
||||||
name: feature.name,
|
name: feature.name,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
@ -6,6 +6,7 @@ import { IUnleashTest, setupAppWithAuth } from '../../helpers/test-helper';
|
|||||||
import { FeatureToggle, WeightType } from '../../../../lib/types/model';
|
import { FeatureToggle, WeightType } from '../../../../lib/types/model';
|
||||||
import getLogger from '../../../fixtures/no-logger';
|
import getLogger from '../../../fixtures/no-logger';
|
||||||
import {
|
import {
|
||||||
|
ALL,
|
||||||
ApiTokenType,
|
ApiTokenType,
|
||||||
IApiToken,
|
IApiToken,
|
||||||
} from '../../../../lib/types/models/api-token';
|
} from '../../../../lib/types/models/api-token';
|
||||||
@ -25,8 +26,8 @@ beforeAll(async () => {
|
|||||||
token = await apiTokenService.createApiTokenWithProjects({
|
token = await apiTokenService.createApiTokenWithProjects({
|
||||||
type: ApiTokenType.ADMIN,
|
type: ApiTokenType.ADMIN,
|
||||||
username: 'tester',
|
username: 'tester',
|
||||||
environment: '*',
|
environment: ALL,
|
||||||
projects: ['*'],
|
projects: [ALL],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -172,7 +173,7 @@ describe('Playground API E2E', () => {
|
|||||||
// get a subset of projects that exist among the features
|
// get a subset of projects that exist among the features
|
||||||
const [projects] = fc.sample(
|
const [projects] = fc.sample(
|
||||||
fc.oneof(
|
fc.oneof(
|
||||||
fc.constant('*' as '*'),
|
fc.constant(ALL as '*'),
|
||||||
fc.uniqueArray(
|
fc.uniqueArray(
|
||||||
fc.constantFrom(
|
fc.constantFrom(
|
||||||
...features.map(
|
...features.map(
|
||||||
@ -194,7 +195,7 @@ describe('Playground API E2E', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
switch (projects) {
|
switch (projects) {
|
||||||
case '*':
|
case ALL:
|
||||||
// no features have been filtered out
|
// no features have been filtered out
|
||||||
return body.features.length === features.length;
|
return body.features.length === features.length;
|
||||||
case []:
|
case []:
|
||||||
@ -228,7 +229,7 @@ describe('Playground API E2E', () => {
|
|||||||
app,
|
app,
|
||||||
token.secret,
|
token.secret,
|
||||||
{
|
{
|
||||||
projects: '*',
|
projects: ALL,
|
||||||
environment: 'default',
|
environment: 'default',
|
||||||
context: {
|
context: {
|
||||||
appName: 'playground-test',
|
appName: 'playground-test',
|
||||||
@ -576,5 +577,59 @@ describe('Playground API E2E', () => {
|
|||||||
testParams,
|
testParams,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('context is applied to variant checks', async () => {
|
||||||
|
const environment = 'development';
|
||||||
|
const featureName = 'feature-name';
|
||||||
|
const customContextFieldName = 'customField';
|
||||||
|
const customContextValue = 'customValue';
|
||||||
|
|
||||||
|
const features = [
|
||||||
|
{
|
||||||
|
project: 'any-project',
|
||||||
|
strategies: [
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
constraints: [
|
||||||
|
{
|
||||||
|
contextName: customContextFieldName,
|
||||||
|
operator: 'IN' as 'IN',
|
||||||
|
values: [customContextValue],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
stale: false,
|
||||||
|
enabled: true,
|
||||||
|
name: featureName,
|
||||||
|
type: 'experiment',
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
name: 'a',
|
||||||
|
weight: 1000,
|
||||||
|
weightType: 'variable',
|
||||||
|
stickiness: 'default',
|
||||||
|
overrides: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
await seedDatabase(db, features, environment);
|
||||||
|
|
||||||
|
const request = {
|
||||||
|
projects: ALL as '*',
|
||||||
|
environment,
|
||||||
|
context: {
|
||||||
|
appName: 'playground',
|
||||||
|
[customContextFieldName]: customContextValue,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const body = await playgroundRequest(app, token.secret, request);
|
||||||
|
|
||||||
|
// when enabled, this toggle should have one of the variants
|
||||||
|
expect(body.features[0].variant.name).toBe('a');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user