Skip to content

Commit 875c04e

Browse files
committed
Respond to PR feedback
1 parent a569976 commit 875c04e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

packages/optimizely-sdk/lib/core/decision_service/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ function DecisionService(options) {
6363
* @return {string|null} the variation the user is bucketed into.
6464
*/
6565
DecisionService.prototype.getVariation = function(experimentKey, userId, attributes) {
66-
attributes = attributes || {};
6766
// by default, the bucketing ID should be the user ID
6867
var bucketingId = this._getBucketingId(userId, attributes);
6968

@@ -113,6 +112,7 @@ DecisionService.prototype.getVariation = function(experimentKey, userId, attribu
113112
* @return {Object} finalized copy of experiment_bucket_map
114113
*/
115114
DecisionService.prototype.__resolveExperimentBucketMap = function(userId, attributes) {
115+
attributes = attributes || {}
116116
var userProfile = this.__getUserProfile(userId) || {};
117117
var attributeExperimentBucketMap = attributes[STICKY_BUCKETING_KEY];
118118
return fns.assignIn({}, userProfile.experiment_bucket_map, attributeExperimentBucketMap);
@@ -201,7 +201,8 @@ DecisionService.prototype.__buildBucketerParams = function(experimentKey, bucket
201201
/**
202202
* Get the stored variation from the user profile for the given experiment
203203
* @param {Object} experiment
204-
* @param {Object} userProfile
204+
* @param {String} userId
205+
* @param {Object} experimentBucketMap mapping experiment => { variation_id: <variationId> }
205206
* @return {Object} the stored variation or null if the user profile does not have one for the given experiment
206207
*/
207208
DecisionService.prototype.__getStoredVariation = function(experiment, userId, experimentBucketMap) {
@@ -221,7 +222,7 @@ DecisionService.prototype.__getStoredVariation = function(experiment, userId, ex
221222
/**
222223
* Get the user profile with the given user ID
223224
* @param {string} userId
224-
* @return {Object} the stored user profile or an empty one if not found
225+
* @return {Object|undefined} the stored user profile or undefined if one isn't found
225226
*/
226227
DecisionService.prototype.__getUserProfile = function(userId) {
227228
var userProfile = {
@@ -252,7 +253,7 @@ DecisionService.prototype.__saveUserProfile = function(experiment, variation, us
252253
}
253254

254255
try {
255-
newBucketMap = fns.cloneDeep(experimentBucketMap);
256+
var newBucketMap = fns.cloneDeep(experimentBucketMap);
256257
newBucketMap[experiment.id] = {
257258
variation_id: variation.id
258259
};

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,19 +296,19 @@ describe('lib/core/decision_service', function() {
296296
assert.strictEqual(mockLogger.log.args[1][1], 'DECISION_SERVICE: Returning previously activated variation \"variation\" of experiment \"testExperiment\" for user \"decision_service_user\" from user profile.');
297297
});
298298

299-
it('should respect ignore attributes for a different experiment id', function () {
299+
it('should ignore attributes for a different experiment id', function () {
300300
userProfileLookupStub.returns({
301301
user_id: 'decision_service_user',
302302
experiment_bucket_map: {
303-
'111127': {
303+
'111127': { // 'testExperiment' ID
304304
'variation_id': '111128' // ID of the 'control' variation
305305
},
306306
},
307307
});
308308

309309
var attributes = {
310310
$opt_experiment_bucket_map: {
311-
'122227': {
311+
'122227': { // other experiment ID
312312
'variation_id': '122229' // ID of the 'variationWithAudience' variation
313313
},
314314
},
@@ -321,19 +321,19 @@ describe('lib/core/decision_service', function() {
321321
assert.strictEqual(mockLogger.log.args[1][1], 'DECISION_SERVICE: Returning previously activated variation \"control\" of experiment \"testExperiment\" for user \"decision_service_user\" from user profile.');
322322
});
323323

324-
it('should use attributes when the userProfileLookup returns null', function () {
324+
it('should use attributes when the userProfileLookup variations for other experiments', function () {
325325
userProfileLookupStub.returns({
326326
user_id: 'decision_service_user',
327327
experiment_bucket_map: {
328-
'122227': {
328+
'122227': { // other experiment ID
329329
'variation_id': '122229' // ID of the 'variationWithAudience' variation
330330
},
331331
}
332332
});
333333

334334
var attributes = {
335335
$opt_experiment_bucket_map: {
336-
'111127': {
336+
'111127': { // 'testExperiment' ID
337337
'variation_id': '111129' // ID of the 'variation' variation
338338
},
339339
},
@@ -346,7 +346,7 @@ describe('lib/core/decision_service', function() {
346346
assert.strictEqual(mockLogger.log.args[1][1], 'DECISION_SERVICE: Returning previously activated variation \"variation\" of experiment \"testExperiment\" for user \"decision_service_user\" from user profile.');
347347
});
348348

349-
it('should use attributes when the userProfileLookup variations for other experiments', function () {
349+
it('should use attributes when the userProfileLookup returns null', function () {
350350
userProfileLookupStub.returns(null);
351351

352352
var attributes = {

0 commit comments

Comments
 (0)