Skip to content

Commit ea1cbfe

Browse files
authored
Merge branch 'master' into fahad/bucketing-id-fix
2 parents 9dccbc9 + cfea9ce commit ea1cbfe

File tree

4 files changed

+112
-4
lines changed

4 files changed

+112
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ DecisionService.prototype._getVariationForFeatureExperiment = function(feature,
315315
var group = this.configObj.groupIdMap[feature.groupId];
316316
if (group) {
317317
experiment = this._getExperimentInGroup(group, userId);
318-
if (experiment) {
318+
if (experiment && feature.experimentIds.indexOf(experiment.id) !== -1) {
319319
variationKey = this.getVariation(experiment.key, userId, attributes);
320320
}
321321
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,18 @@ describe('lib/core/decision_service', function() {
889889
assert.deepEqual(decision, expectedDecision);
890890
sinon.assert.calledWithExactly(mockLogger.log, LOG_LEVEL.DEBUG, 'DECISION_SERVICE: User user1 is not in any experiment on the feature feature_with_group.');
891891
});
892+
893+
it('returns null decision for group experiment not referenced by the feature', function() {
894+
var noTrafficExpFeature = configObj.featureKeyMap.feature_exp_no_traffic;
895+
var decision = decisionServiceInstance.getVariationForFeature(noTrafficExpFeature, 'user1');
896+
var expectedDecision = {
897+
experiment: null,
898+
variation: null,
899+
decisionSource: null,
900+
};
901+
assert.deepEqual(decision, expectedDecision);
902+
sinon.assert.calledWithExactly(mockLogger.log, LOG_LEVEL.DEBUG, 'DECISION_SERVICE: User user1 is not in any experiment on the feature feature_exp_no_traffic.');
903+
});
892904
});
893905

894906
describe('user not bucketed into the group', function() {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016-2018, Optimizely, Inc. and contributors *
2+
* Copyright 2016-2019, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -2991,7 +2991,7 @@ describe('lib/optimizely', function() {
29912991
assert.strictEqual(result.length, 2);
29922992
assert.isAbove(result.indexOf('test_feature'), -1);
29932993
assert.isAbove(result.indexOf('test_feature_for_experiment'), -1);
2994-
sinon.assert.callCount(optlyInstance.isFeatureEnabled, 6);
2994+
sinon.assert.callCount(optlyInstance.isFeatureEnabled, 7);
29952995
sinon.assert.calledWithExactly(
29962996
optlyInstance.isFeatureEnabled,
29972997
'test_feature',
@@ -3028,6 +3028,12 @@ describe('lib/optimizely', function() {
30283028
'user1',
30293029
attributes
30303030
);
3031+
sinon.assert.calledWithExactly(
3032+
optlyInstance.isFeatureEnabled,
3033+
'feature_exp_no_traffic',
3034+
'user1',
3035+
attributes
3036+
);
30313037
});
30323038
});
30333039

packages/optimizely-sdk/lib/tests/test_data.js

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018, Optimizely
2+
* Copyright 2016-2019, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -429,6 +429,15 @@ var configWithFeatures = {
429429
'id': '599110',
430430
'experimentIds': [],
431431
'variables': []
432+
},
433+
{
434+
'rolloutId': '',
435+
'key': 'feature_exp_no_traffic',
436+
'id': '4482920079',
437+
'experimentIds': [
438+
'12115595439'
439+
],
440+
'variables': []
432441
}
433442
],
434443
'experiments': [
@@ -637,6 +646,74 @@ var configWithFeatures = {
637646
'entityId': '599082'
638647
}
639648
]
649+
},
650+
{
651+
'policy': 'random',
652+
'id': '595025',
653+
'experiments': [
654+
{
655+
'trafficAllocation': [
656+
{
657+
'endOfRange': 10000,
658+
'entityId': '12098126627'
659+
}
660+
],
661+
'layerId': '595005',
662+
'forcedVariations': {},
663+
'audienceIds': [],
664+
'variations': [
665+
{
666+
'key': 'all_traffic_variation',
667+
'id': '12098126627',
668+
'variables': []
669+
},
670+
{
671+
'key': 'no_traffic_variation',
672+
'id': '12098126628',
673+
'variables': []
674+
}
675+
],
676+
'status': 'Running',
677+
'key': 'all_traffic_experiment',
678+
'id': '12198292375'
679+
},
680+
{
681+
'trafficAllocation': [
682+
{
683+
'endOfRange': 5000,
684+
'entityId': '12098126629'
685+
},
686+
{
687+
'endOfRange': 10000,
688+
'entityId': '12098126630'
689+
}
690+
],
691+
'layerId': '12187694826',
692+
'forcedVariations': {},
693+
'audienceIds': [],
694+
'variations': [
695+
{
696+
'key': 'variation_5000',
697+
'id': '12098126629',
698+
'variables': []
699+
},
700+
{
701+
'key': 'variation_10000',
702+
'id': '12098126630',
703+
'variables': []
704+
}
705+
],
706+
'status': 'Running',
707+
'key': 'no_traffic_experiment',
708+
'id': '12115595439'
709+
}
710+
],
711+
'trafficAllocation': [
712+
{
713+
'endOfRange': 10000,
714+
'entityId': '12198292375'
715+
}
716+
]
640717
}
641718
],
642719
'attributes': [
@@ -1333,6 +1410,10 @@ var datafileWithFeaturesExpectedData = {
13331410
},
13341411
599080: {},
13351412
599081: {},
1413+
12098126627: {},
1414+
12098126628: {},
1415+
12098126629: {},
1416+
12098126630: {},
13361417
},
13371418

13381419
featureKeyMap: {
@@ -1547,6 +1628,15 @@ var datafileWithFeaturesExpectedData = {
15471628
'variables': [],
15481629
variableKeyMap: {},
15491630
},
1631+
feature_exp_no_traffic: {
1632+
'rolloutId': '',
1633+
'key': 'feature_exp_no_traffic',
1634+
'id': '4482920079',
1635+
'experimentIds': ['12115595439'],
1636+
'variables': [],
1637+
variableKeyMap: {},
1638+
groupId: '595025',
1639+
},
15501640
},
15511641
};
15521642

0 commit comments

Comments
 (0)