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[]> {
|
||||
await variantsArraySchema.validateAsync(newVariants);
|
||||
const fixedVariants = this.fixVariantWeights(newVariants);
|
||||
const oldVariants: { [env: string]: IVariant[] } = environments.reduce(
|
||||
async (result, environment) => {
|
||||
result[environment] = await this.featureEnvironmentStore.get({
|
||||
const oldVariants: { [env: string]: IVariant[] } = {};
|
||||
for (const env of environments) {
|
||||
const featureEnv = await this.featureEnvironmentStore.get({
|
||||
featureName,
|
||||
environment,
|
||||
environment: env,
|
||||
});
|
||||
return result;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
oldVariants[env] = featureEnv.variants || [];
|
||||
}
|
||||
await this.eventStore.batchStore(
|
||||
environments.map(
|
||||
(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 () => {
|
||||
const featureName = 'feature-variants-patch-add';
|
||||
const variantName = 'fancy-variant-patch';
|
||||
|
Loading…
Reference in New Issue
Block a user