Skip to content

Commit

Permalink
fix: variant stickiness from strategy (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Jan 23, 2024
1 parent 8fa90e2 commit da6120b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@types/sinon": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@unleash/client-specification": "^5.1.0",
"@unleash/client-specification": "^5.1.4",
"ava": "^5.3.0",
"coveralls": "^3.1.1",
"cross-env": "^7.0.3",
Expand Down
3 changes: 2 additions & 1 deletion src/strategy/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ export class Strategy {
this.isEnabledWithConstraints(parameters, context, constraints);

if (enabled && Array.isArray(variants) && variants.length > 0) {
const stickiness = variants[0].stickiness || parameters.stickiness;
const variantDefinition =
selectVariantDefinition(parameters.groupId, variants, context);
selectVariantDefinition(parameters.groupId, stickiness, variants, context);
return variantDefinition ? {
enabled: true,
variant: {
Expand Down
6 changes: 3 additions & 3 deletions src/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function findOverride(

export function selectVariantDefinition(
groupId: string,
stickiness: string | undefined,
variants: VariantDefinition[],
context: Context,
): VariantDefinition | null {
Expand All @@ -110,8 +111,6 @@ export function selectVariantDefinition(
return variantOverride;
}

const { stickiness } = variants[0];

const target = normalizedVariantValue(getSeed(context, stickiness), groupId, totalWeight);

let counter = 0;
Expand All @@ -132,5 +131,6 @@ export function selectVariant(
feature: FeatureInterface,
context: Context,
): VariantDefinition | null {
return selectVariantDefinition(feature.name, feature.variants || [], context);
const stickiness = feature.variants?.[0]?.stickiness ?? undefined;
return selectVariantDefinition(feature.name, stickiness, feature.variants || [], context);
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,10 @@
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==

"@unleash/client-specification@^5.1.0":
version "5.1.3"
resolved "https://registry.yarnpkg.com/@unleash/client-specification/-/client-specification-5.1.3.tgz#660090a0b96aef3eeb4086f40c4aa9fdf4cebdec"
integrity sha512-52QcYjKZ/OqvOPgqtnr5HLke1Aqdgs/bYZa/byYD+LQ40SW1EJB1vUcSsMdEYWMuW4j533g24mMs1DZhkG+dvQ==
"@unleash/client-specification@^5.1.4":
version "5.1.4"
resolved "https://registry.yarnpkg.com/@unleash/client-specification/-/client-specification-5.1.4.tgz#5e5df5749bb6828f127020771c5f9150d7b0e4c8"
integrity sha512-zJMQT0olV9LKlYXbgJrnv08Tbh6G+tXh9s07Z8UvCroItmxJEO/+f6lIhtZh5b+79TdrROt8Sg85mAr+rRnhlQ==

acorn-jsx@^5.3.2:
version "5.3.2"
Expand Down

0 comments on commit da6120b

Please sign in to comment.