Skip to content

Commit f59ed37

Browse files
authored
fix: Serve correct variation when rule keys are not unique for flags 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
1 parent a4dcc3e commit f59ed37

File tree

8 files changed

+123
-101
lines changed

8 files changed

+123
-101
lines changed

packages/optimizely-sdk/lib/core/bucketer/index.tests.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('lib/core/bucketer', function() {
5353
experimentKey: configObj.experiments[0].key,
5454
trafficAllocationConfig: configObj.experiments[0].trafficAllocation,
5555
variationIdMap: configObj.variationIdMap,
56-
experimentKeyMap: configObj.experimentKeyMap,
56+
experimentIdMap: configObj.experimentIdMap,
5757
groupIdMap: configObj.groupIdMap,
5858
logger: createdLogger,
5959
};
@@ -101,7 +101,7 @@ describe('lib/core/bucketer', function() {
101101
experimentKey: configObj.experiments[0].key,
102102
trafficAllocationConfig: configObj.experiments[0].trafficAllocation,
103103
variationIdMap: configObj.variationIdMap,
104-
experimentKeyMap: configObj.experimentKeyMap,
104+
experimentIdMap: configObj.experimentIdMap,
105105
groupIdMap: configObj.groupIdMap,
106106
logger: createdLogger,
107107
};
@@ -120,7 +120,7 @@ describe('lib/core/bucketer', function() {
120120
experimentKey: configObj.experiments[4].key,
121121
trafficAllocationConfig: configObj.experiments[4].trafficAllocation,
122122
variationIdMap: configObj.variationIdMap,
123-
experimentKeyMap: configObj.experimentKeyMap,
123+
experimentIdMap: configObj.experimentIdMap,
124124
groupIdMap: configObj.groupIdMap,
125125
logger: createdLogger,
126126
userId: 'testUser',
@@ -220,7 +220,7 @@ describe('lib/core/bucketer', function() {
220220

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

225225
assert.throws(function() {
226226
bucketer.bucket(bucketerParamsWithInvalidGroupId);
@@ -236,7 +236,7 @@ describe('lib/core/bucketer', function() {
236236
experimentKey: configObj.experiments[6].key,
237237
trafficAllocationConfig: configObj.experiments[6].trafficAllocation,
238238
variationIdMap: configObj.variationIdMap,
239-
experimentKeyMap: configObj.experimentKeyMap,
239+
experimentIdMap: configObj.experimentIdMap,
240240
groupIdMap: configObj.groupIdMap,
241241
logger: createdLogger,
242242
userId: 'testUser',
@@ -282,7 +282,7 @@ describe('lib/core/bucketer', function() {
282282
},
283283
],
284284
variationIdMap: configObj.variationIdMap,
285-
experimentKeyMap: configObj.experimentKeyMap,
285+
experimentIdMap: configObj.experimentIdMap,
286286
groupIdMap: configObj.groupIdMap,
287287
logger: createdLogger,
288288
};
@@ -322,7 +322,7 @@ describe('lib/core/bucketer', function() {
322322
},
323323
],
324324
variationIdMap: configObj.variationIdMap,
325-
experimentKeyMap: configObj.experimentKeyMap,
325+
experimentIdMap: configObj.experimentIdMap,
326326
groupIdMap: configObj.groupIdMap,
327327
logger: createdLogger,
328328
};
@@ -370,7 +370,7 @@ describe('lib/core/bucketer', function() {
370370
bucketerParams = {
371371
trafficAllocationConfig: configObj.experiments[0].trafficAllocation,
372372
variationIdMap: configObj.variationIdMap,
373-
experimentKeyMap: configObj.experimentKeyMap,
373+
experimentIdMap: configObj.experimentIdMap,
374374
groupIdMap: configObj.groupIdMap,
375375
logger: createdLogger,
376376
};

packages/optimizely-sdk/lib/core/bucketer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const RANDOM_POLICY = 'random';
5858
export const bucket = function(bucketerParams: BucketerParams): DecisionResponse<string | null> {
5959
const decideReasons: string[] = [];
6060
// Check if user is in a random group; if so, check if user is bucketed into a specific experiment
61-
const experiment = bucketerParams.experimentKeyMap[bucketerParams.experimentKey];
61+
const experiment = bucketerParams.experimentIdMap[bucketerParams.experimentId];
6262
const groupId = experiment['groupId'];
6363
if (groupId) {
6464
const group = bucketerParams.groupIdMap[groupId];

0 commit comments

Comments
 (0)