1
0
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:
Tymoteusz Czech 2023-07-12 17:14:55 +02:00 committed by GitHub
parent b927615ebe
commit fb9db12002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View File

@ -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) =>

View File

@ -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';