Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 5cf29fc

Browse files
authored
Add feature toggleability at the variation level. (optimizely#78)
1 parent 2e7b9b2 commit 5cf29fc

File tree

5 files changed

+279
-165
lines changed

5 files changed

+279
-165
lines changed

lib/core/decision_service/index.tests.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ describe('lib/core/decision_service', function() {
526526
'value': '20.25'
527527
}
528528
],
529+
'featureEnabled': true,
529530
'key': 'variation'
530531
},
531532
{
@@ -548,6 +549,7 @@ describe('lib/core/decision_service', function() {
548549
'value': '50.55'
549550
}
550551
],
552+
'featureEnabled': true,
551553
'key': 'control'
552554
}
553555
],
@@ -578,6 +580,7 @@ describe('lib/core/decision_service', function() {
578580
'value': '50.55'
579581
}
580582
],
583+
'featureEnabled': true,
581584
'key': 'control'
582585
},
583586
variation: {
@@ -600,6 +603,7 @@ describe('lib/core/decision_service', function() {
600603
'value': '20.25'
601604
}
602605
],
606+
'featureEnabled': true,
603607
'key': 'variation'
604608
},
605609
},
@@ -624,6 +628,7 @@ describe('lib/core/decision_service', function() {
624628
'value': '20.25'
625629
}
626630
],
631+
'featureEnabled': true,
627632
'key': 'variation'
628633
},
629634
decisionSource: DECISION_SOURCES.EXPERIMENT,
@@ -789,6 +794,7 @@ describe('lib/core/decision_service', function() {
789794
'value': 'Hello audience'
790795
}
791796
],
797+
'featureEnabled': true,
792798
'key': '594032'
793799
}],
794800
variationKeyMap: {
@@ -812,6 +818,7 @@ describe('lib/core/decision_service', function() {
812818
'value': 'Hello audience'
813819
}
814820
],
821+
'featureEnabled': true,
815822
'key': '594032'
816823
},
817824
},
@@ -839,6 +846,7 @@ describe('lib/core/decision_service', function() {
839846
'value': 'Hello audience'
840847
}
841848
],
849+
'featureEnabled': true,
842850
'key': '594032'
843851
},
844852
decisionSource: DECISION_SOURCES.ROLLOUT,
@@ -884,6 +892,7 @@ describe('lib/core/decision_service', function() {
884892
'value': 'Hello'
885893
}
886894
],
895+
'featureEnabled': false,
887896
'key': '594038'
888897
}],
889898
'audienceIds': [],
@@ -910,6 +919,7 @@ describe('lib/core/decision_service', function() {
910919
'value': 'Hello'
911920
}
912921
],
922+
'featureEnabled': false,
913923
'key': '594038'
914924
},
915925
},
@@ -934,6 +944,7 @@ describe('lib/core/decision_service', function() {
934944
'value': 'Hello'
935945
}
936946
],
947+
'featureEnabled': false,
937948
'key': '594038'
938949
},
939950
decisionSource: DECISION_SOURCES.ROLLOUT,
@@ -1000,6 +1011,7 @@ describe('lib/core/decision_service', function() {
10001011
'value': 'Hello'
10011012
}
10021013
],
1014+
'featureEnabled': false,
10031015
'key': '594038'
10041016
}],
10051017
'audienceIds': [],
@@ -1026,6 +1038,7 @@ describe('lib/core/decision_service', function() {
10261038
'value': 'Hello'
10271039
}
10281040
],
1041+
'featureEnabled': false,
10291042
'key': '594038'
10301043
},
10311044
},
@@ -1050,6 +1063,7 @@ describe('lib/core/decision_service', function() {
10501063
'value': 'Hello'
10511064
}
10521065
],
1066+
'featureEnabled': false,
10531067
'key': '594038'
10541068
},
10551069
decisionSource: DECISION_SOURCES.ROLLOUT,
@@ -1093,6 +1107,7 @@ describe('lib/core/decision_service', function() {
10931107
{
10941108
'key': '599057',
10951109
'id': '599057',
1110+
'featureEnabled': true,
10961111
'variables': [
10971112
{
10981113
'id': '4937719889264640',
@@ -1112,6 +1127,7 @@ describe('lib/core/decision_service', function() {
11121127
599057: {
11131128
'key': '599057',
11141129
'id': '599057',
1130+
'featureEnabled': true,
11151131
'variables': [
11161132
{
11171133
'id': '4937719889264640',
@@ -1128,6 +1144,7 @@ describe('lib/core/decision_service', function() {
11281144
variation: {
11291145
'key': '599057',
11301146
'id': '599057',
1147+
'featureEnabled': true,
11311148
'variables': [
11321149
{
11331150
'id': '4937719889264640',

lib/core/project_config/index.tests.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ describe('lib/core/project_config', function() {
172172
{ 'value': '4.99', 'id': '6045752732155904' },
173173
{ 'value': 'Hello audience', 'id': '6327227708866560' }
174174
],
175+
'featureEnabled': true,
175176
'key': '594032',
176177
'id': '594032'
177178
});
@@ -182,6 +183,7 @@ describe('lib/core/project_config', function() {
182183
{ 'value': '14.99', 'id': '6045752732155904' },
183184
{ 'value': 'Hello', 'id': '6327227708866560' },
184185
],
186+
'featureEnabled': false,
185187
'key': '594038',
186188
'id': '594038'
187189
});
@@ -192,6 +194,7 @@ describe('lib/core/project_config', function() {
192194
{ 'value': '10003', 'id': '6186490220511232' },
193195
{ 'value': 'false', 'id': '6467965197221888' },
194196
],
197+
'featureEnabled': true,
195198
'key': '594061',
196199
'id': '594061'
197200
});
@@ -202,6 +205,7 @@ describe('lib/core/project_config', function() {
202205
{ 'value': '500', 'id': '6186490220511232' },
203206
{ 'value': 'true', 'id': '6467965197221888' }
204207
],
208+
'featureEnabled': true,
205209
'key': '594067',
206210
'id': '594067',
207211
});

lib/optimizely/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,17 +483,17 @@ Optimizely.prototype.isFeatureEnabled = function(featureKey, userId, attributes)
483483
}
484484

485485
var decision = this.decisionService.getVariationForFeature(feature, userId, attributes);
486-
var featureEnabled = !!decision.variation;
487-
if (featureEnabled) {
486+
var variation = decision.variation;
487+
if (!!variation && variation.featureEnabled === true) {
488488
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
489489
if (decision.decisionSource === DECISION_SOURCES.EXPERIMENT) {
490490
this._sendImpressionEvent(decision.experiment.key, decision.variation.key, userId, attributes);
491491
}
492+
return true;
492493
} else {
493494
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.FEATURE_NOT_ENABLED_FOR_USER, MODULE_NAME, featureKey, userId));
495+
return false;
494496
}
495-
496-
return featureEnabled;
497497
};
498498

499499
/**

0 commit comments

Comments
 (0)