mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
Fix: variants-batch (#4222)
## About the changes Fix un-awaited promise on batch variant update - reduce function allowed TS to skip Promise type. --------- Co-authored-by: Gastón Fournier <gaston@getunleash.io>
This commit is contained in:
parent
b927615ebe
commit
fb9db12002
@ -1837,17 +1837,14 @@ class FeatureToggleService {
|
|||||||
): Promise<IVariant[]> {
|
): Promise<IVariant[]> {
|
||||||
await variantsArraySchema.validateAsync(newVariants);
|
await variantsArraySchema.validateAsync(newVariants);
|
||||||
const fixedVariants = this.fixVariantWeights(newVariants);
|
const fixedVariants = this.fixVariantWeights(newVariants);
|
||||||
const oldVariants: { [env: string]: IVariant[] } = environments.reduce(
|
const oldVariants: { [env: string]: IVariant[] } = {};
|
||||||
async (result, environment) => {
|
for (const env of environments) {
|
||||||
result[environment] = await this.featureEnvironmentStore.get({
|
const featureEnv = await this.featureEnvironmentStore.get({
|
||||||
featureName,
|
featureName,
|
||||||
environment,
|
environment: env,
|
||||||
});
|
});
|
||||||
return result;
|
oldVariants[env] = featureEnv.variants || [];
|
||||||
},
|
}
|
||||||
{},
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.eventStore.batchStore(
|
await this.eventStore.batchStore(
|
||||||
environments.map(
|
environments.map(
|
||||||
(environment) =>
|
(environment) =>
|
||||||
|
@ -305,6 +305,25 @@ test('Can push variants to multiple environments', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Returns proper error if project and/or feature toggle doesn't exist", async () => {
|
||||||
|
await app.request
|
||||||
|
.put(
|
||||||
|
`/api/admin/projects/nonexistent/features/undefined/variants-batch`,
|
||||||
|
)
|
||||||
|
.send({
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
name: 'new-variant-1',
|
||||||
|
stickiness: 'default',
|
||||||
|
weight: 500,
|
||||||
|
weightType: WeightType.VARIABLE,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
environments: ['development', 'production'],
|
||||||
|
})
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
|
||||||
test('Can add variant for a feature', async () => {
|
test('Can add variant for a feature', async () => {
|
||||||
const featureName = 'feature-variants-patch-add';
|
const featureName = 'feature-variants-patch-add';
|
||||||
const variantName = 'fancy-variant-patch';
|
const variantName = 'fancy-variant-patch';
|
||||||
|
Loading…
Reference in New Issue
Block a user