Skip to content

Commit

Permalink
fix: Serve correct variation when rule keys are not unique for flags …
Browse files Browse the repository at this point in the history
…in a project (#687)

* WIP

* Fix bucketer unit tests

* Fix decision_service unit tests WIP

* Wrap up decision_service unit tests

* Fix project_config unit tests

* Incorporate comments
  • Loading branch information
yavorona committed Jul 8, 2021
1 parent 88fded0 commit 576b48c
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 101 deletions.
16 changes: 8 additions & 8 deletions packages/optimizely-sdk/lib/core/bucketer/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('lib/core/bucketer', function() {
experimentKey: configObj.experiments[0].key,
trafficAllocationConfig: configObj.experiments[0].trafficAllocation,
variationIdMap: configObj.variationIdMap,
experimentKeyMap: configObj.experimentKeyMap,
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
};
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('lib/core/bucketer', function() {
experimentKey: configObj.experiments[0].key,
trafficAllocationConfig: configObj.experiments[0].trafficAllocation,
variationIdMap: configObj.variationIdMap,
experimentKeyMap: configObj.experimentKeyMap,
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
};
Expand All @@ -120,7 +120,7 @@ describe('lib/core/bucketer', function() {
experimentKey: configObj.experiments[4].key,
trafficAllocationConfig: configObj.experiments[4].trafficAllocation,
variationIdMap: configObj.variationIdMap,
experimentKeyMap: configObj.experimentKeyMap,
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
userId: 'testUser',
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('lib/core/bucketer', function() {

it('should throw an error if group ID is not in the datafile', function() {
var bucketerParamsWithInvalidGroupId = cloneDeep(bucketerParams);
bucketerParamsWithInvalidGroupId.experimentKeyMap[configObj.experiments[4].key].groupId = '6969';
bucketerParamsWithInvalidGroupId.experimentIdMap[configObj.experiments[4].id].groupId = '6969';

assert.throws(function() {
bucketer.bucket(bucketerParamsWithInvalidGroupId);
Expand All @@ -236,7 +236,7 @@ describe('lib/core/bucketer', function() {
experimentKey: configObj.experiments[6].key,
trafficAllocationConfig: configObj.experiments[6].trafficAllocation,
variationIdMap: configObj.variationIdMap,
experimentKeyMap: configObj.experimentKeyMap,
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
userId: 'testUser',
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('lib/core/bucketer', function() {
},
],
variationIdMap: configObj.variationIdMap,
experimentKeyMap: configObj.experimentKeyMap,
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
};
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('lib/core/bucketer', function() {
},
],
variationIdMap: configObj.variationIdMap,
experimentKeyMap: configObj.experimentKeyMap,
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
};
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('lib/core/bucketer', function() {
bucketerParams = {
trafficAllocationConfig: configObj.experiments[0].trafficAllocation,
variationIdMap: configObj.variationIdMap,
experimentKeyMap: configObj.experimentKeyMap,
experimentIdMap: configObj.experimentIdMap,
groupIdMap: configObj.groupIdMap,
logger: createdLogger,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/core/bucketer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const RANDOM_POLICY = 'random';
export const bucket = function(bucketerParams: BucketerParams): DecisionResponse<string | null> {
const decideReasons: string[] = [];
// Check if user is in a random group; if so, check if user is bucketed into a specific experiment
const experiment = bucketerParams.experimentKeyMap[bucketerParams.experimentKey];
const experiment = bucketerParams.experimentIdMap[bucketerParams.experimentId];
const groupId = experiment['groupId'];
if (groupId) {
const group = bucketerParams.groupIdMap[groupId];
Expand Down
Loading

0 comments on commit 576b48c

Please sign in to comment.