Skip to content

Commit

Permalink
fix(repartitions): for progressive percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrachet committed Oct 17, 2024
1 parent 03a6c7a commit fe3ffa9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@flag-engine/core",
"private": false,
"version": "0.0.6",
"version": "0.0.7",
"description": "Feature flags evaluation engine, runtime agnostic",
"type": "module",
"main": "./dist/index.cjs.js",
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe("api", () => {
expect(userCtx.evaluateAll()).toEqual({ "new-homepage": false });
});

it("returns 'Control' variant when the flag is enabled and with __id being 'A'", () => {
it("returns 'Control' variant when the flag is enabled and with __id being 'Ab'", () => {
const flagsConfig: FlagsConfiguration = [
{
key: "new-homepage",
Expand All @@ -227,14 +227,14 @@ describe("api", () => {

const engine = createFlagEngine(flagsConfig);
const userCtx = engine.createUserContext({
__id: "A",
__id: "Ab",
notMatching: "hello",
});

expect(userCtx.evaluateAll()).toEqual({ "new-homepage": "Control" });
});

it("returns 'B' variant when the flag is enabled and with __id being 'yo'", () => {
it("returns 'B' variant when the flag is enabled and with __id being 'A'", () => {
const flagsConfig: FlagsConfiguration = [
{
key: "new-homepage",
Expand All @@ -260,14 +260,14 @@ describe("api", () => {

const engine = createFlagEngine(flagsConfig);
const userCtx = engine.createUserContext({
__id: "a,",
__id: "A",
notMatching: "hello",
});

expect(userCtx.evaluateAll()).toEqual({ "new-homepage": "B" });
});

it("resolves the variants 'Control' of the matching strategy for the __id 'A'", () => {
it("resolves the variants 'Control' of the matching strategy for the __id 'a,'", () => {
const flagsConfig: FlagsConfiguration = [
{
key: "new-homepage",
Expand Down Expand Up @@ -324,7 +324,7 @@ describe("api", () => {

const engine = createFlagEngine(flagsConfig);
const userCtx = engine.createUserContext({
__id: "A",
__id: "a,",
firstName: "marvin",
lastName: "frachet",
country: "FR",
Expand All @@ -333,7 +333,7 @@ describe("api", () => {
expect(userCtx.evaluateAll()).toEqual({ "new-homepage": "Control" });
});

it("resolves the variants 'B' of the matching strategy for the __id 'yo'", () => {
it("resolves the variants 'B' of the matching strategy for the __id 'A'", () => {
const flagsConfig: FlagsConfiguration = [
{
key: "new-homepage",
Expand Down Expand Up @@ -390,7 +390,7 @@ describe("api", () => {

const engine = createFlagEngine(flagsConfig);
const userCtx = engine.createUserContext({
__id: "a,",
__id: "A",
firstName: "marvin",
lastName: "frachet",
country: "FR",
Expand Down Expand Up @@ -531,7 +531,7 @@ describe("api", () => {
];
const engine = createFlagEngine(flagsConfig);
const userCtx = engine.createUserContext({
__id: "b",
__id: "a",
country: "France",
});

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/resolveStrategyVariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export const resolveStrategyVariant = (strategy: Strategy, userKey: string) => {

let cumulative = 0;

const murmurkey = `${strategy.name}-${userKey}`;

const variant = strategy.variants.find((variant) => {
const hash = murmur3(userKey);
const hash = murmur3(murmurkey);
const userFlagPercentage = (hash / MAX_INT_32) * 100;

cumulative += variant.percent;
Expand Down

0 comments on commit fe3ffa9

Please sign in to comment.