mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat: default session id in frontend api (#5083)
This commit is contained in:
parent
f8fba501ae
commit
1f8d12bcdc
@ -74,12 +74,19 @@ export class ProxyService {
|
|||||||
const client = await this.clientForProxyToken(token);
|
const client = await this.clientForProxyToken(token);
|
||||||
const definitions = client.getFeatureToggleDefinitions() || [];
|
const definitions = client.getFeatureToggleDefinitions() || [];
|
||||||
|
|
||||||
|
const sessionId = context.sessionId || String(Math.random());
|
||||||
|
|
||||||
return definitions
|
return definitions
|
||||||
.filter((feature) => client.isEnabled(feature.name, context))
|
.filter((feature) =>
|
||||||
|
client.isEnabled(feature.name, { ...context, sessionId }),
|
||||||
|
)
|
||||||
.map((feature) => ({
|
.map((feature) => ({
|
||||||
name: feature.name,
|
name: feature.name,
|
||||||
enabled: Boolean(feature.enabled),
|
enabled: Boolean(feature.enabled),
|
||||||
variant: client.forceGetVariant(feature.name, context),
|
variant: client.getVariant(feature.name, {
|
||||||
|
...context,
|
||||||
|
sessionId,
|
||||||
|
}),
|
||||||
impressionData: Boolean(feature.impressionData),
|
impressionData: Boolean(feature.impressionData),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -1236,3 +1236,43 @@ test('should return 204 if metrics are disabled', async () => {
|
|||||||
})
|
})
|
||||||
.expect(204);
|
.expect(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should resolve variable rollout percentage consistently', async () => {
|
||||||
|
const frontendToken = await createApiToken(ApiTokenType.FRONTEND);
|
||||||
|
await createFeatureToggle({
|
||||||
|
name: 'randomFeature',
|
||||||
|
enabled: true,
|
||||||
|
strategies: [
|
||||||
|
{
|
||||||
|
name: 'flexibleRollout',
|
||||||
|
constraints: [],
|
||||||
|
parameters: {
|
||||||
|
rollout: '50',
|
||||||
|
stickiness: 'default',
|
||||||
|
groupId: 'some-new',
|
||||||
|
},
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
name: 'a',
|
||||||
|
stickiness: 'default',
|
||||||
|
weightType: 'variable',
|
||||||
|
weight: 1000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i = 0; i < 10; ++i) {
|
||||||
|
const { body } = await app.request
|
||||||
|
.get('/api/frontend')
|
||||||
|
.set('Authorization', frontendToken.secret)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
if (body.toggles.length > 0) {
|
||||||
|
// disabled variant should not be possible for enabled toggles
|
||||||
|
expect(body.toggles[0].variant.name).toBe('a');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user