Skip to content

feat(api): Decision Notification Listener for feature variable APIs. #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eabb383
feat(api): OnDecision Notification Listener for feature variable APIs.
mfahadahmed Mar 8, 2019
f401d21
Implement suggested changes.
mfahadahmed Mar 12, 2019
167294c
Separate out the unit tests for decision listener.
mfahadahmed Mar 12, 2019
26f63e3
Reverted existing unit tests.
mfahadahmed Mar 12, 2019
5d6fe51
Merge remote-tracking branch 'origin/master' into fahad/on-decision-l…
mfahadahmed Mar 13, 2019
8c80556
Capitalize decision source values.
mfahadahmed Mar 13, 2019
cd0e313
Revert decision_service tests change.
mfahadahmed Mar 13, 2019
c6dd63a
getVariationForFeature method now returns decision source as rollout …
mfahadahmed Mar 14, 2019
79ea03d
Address code review comments.
mfahadahmed Mar 14, 2019
2dec469
Revert "Revert decision_service tests change." commit.
mfahadahmed Mar 14, 2019
82b3ce4
Address code review comments.
mfahadahmed Mar 14, 2019
0256e7c
Merge remote-tracking branch 'origin/master' into fahad/on-decision-l…
mfahadahmed Mar 15, 2019
01f0288
Adds new variation with featureEnabled set to false for feature varia…
mfahadahmed Mar 19, 2019
49802a2
Merge remote-tracking branch 'origin/master' into fahad/on-decision-l…
mfahadahmed Mar 19, 2019
24a61e3
Modified data file.
mfahadahmed Mar 19, 2019
d66dc1e
Modified data file.
mfahadahmed Mar 19, 2019
56a07f1
Remove quotes.
mfahadahmed Mar 19, 2019
1f4987b
Return right variable value from variation when featureEnabled is false.
mfahadahmed Mar 25, 2019
473686f
Return right variable value from variation when featureEnabled is false.
mfahadahmed Mar 25, 2019
1b191cf
Fix indentation.
mfahadahmed Mar 25, 2019
bb6bfa9
Merge remote-tracking branch 'origin/master' into fahad/on-decision-l…
mfahadahmed Mar 28, 2019
ea581e0
Merge remote-tracking branch 'origin/master' into fahad/on-decision-l…
mfahadahmed Mar 29, 2019
69fb7d6
Merge remote-tracking branch 'origin/master' into fahad/on-decision-l…
mfahadahmed Apr 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/optimizely-sdk/lib/core/decision_service/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,29 @@ describe('lib/core/decision_service', function() {
],
'featureEnabled': true,
'key': 'control'
},
{
'id': '594099',
'variables': [
{
'id': '4792309476491264',
'value': '40'
},
{
'id': '5073784453201920',
'value': 'true'
},
{
'id': '5636734406623232',
'value': 'Buy me Later'
},
{
'id': '6199684360044544',
'value': '99.99'
}
],
'featureEnabled': false,
'key': 'variation2'
}
],
'audienceIds': [],
Expand Down Expand Up @@ -798,6 +821,29 @@ describe('lib/core/decision_service', function() {
'featureEnabled': true,
'key': 'variation'
},
variation2: {
'id': '594099',
'variables': [
{
'id': '4792309476491264',
'value': '40'
},
{
'id': '5073784453201920',
'value': 'true'
},
{
'id': '5636734406623232',
'value': 'Buy me Later'
},
{
'id': '6199684360044544',
'value': '99.99'
}
],
'featureEnabled': false,
'key': 'variation2'
}
},
},
variation: {
Expand Down
57 changes: 34 additions & 23 deletions packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,35 +632,46 @@ Optimizely.prototype._getFeatureVariableForType = function(featureKey, variableK
return null;
}

var decision = this.decisionService.getVariationForFeature(this.configObj, featureFlag, userId, attributes);
var variableValue;
var featureEnabled = false;
var decision = this.decisionService.getVariationForFeature(this.configObj, featureFlag, userId, attributes);

if (decision.variation !== null) {
variableValue = projectConfig.getVariableValueForVariation(
this.configObj,
variable,
decision.variation,
this.logger
);
this.logger.log(
LOG_LEVEL.INFO,
sprintf(
LOG_MESSAGES.USER_RECEIVED_VARIABLE_VALUE,
MODULE_NAME,
variableKey,
featureFlag.key,
variableValue,
userId
)
);
featureEnabled = decision.variation.featureEnabled;
variableValue = projectConfig.getVariableValueForVariation(this.configObj, variable, decision.variation, this.logger);
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.USER_RECEIVED_VARIABLE_VALUE, MODULE_NAME, variableKey, featureFlag.key, variableValue, userId));
} else {
variableValue = variable.defaultValue;
this.logger.log(
LOG_LEVEL.INFO,
sprintf(LOG_MESSAGES.USER_RECEIVED_DEFAULT_VARIABLE_VALUE, MODULE_NAME, userId, variableKey, featureFlag.key)
);
this.logger.log(LOG_LEVEL.INFO, sprintf(LOG_MESSAGES.USER_RECEIVED_DEFAULT_VARIABLE_VALUE, MODULE_NAME, userId, variableKey, featureFlag.key));
}

return projectConfig.getTypeCastValue(variableValue, variableType, this.logger);
var experimentKey = null;
var variationKey = null;
if (decision.decisionSource === DECISION_SOURCES.EXPERIMENT) {
experimentKey = decision.experiment.key;
variationKey = decision.variation.key;
}

var typeCastedValue = projectConfig.getTypeCastValue(variableValue, variableType, this.logger);
this.notificationCenter.sendNotifications(
enums.NOTIFICATION_TYPES.DECISION,
{
type: DECISION_INFO_TYPES.FEATURE_VARIABLE,
userId: userId,
attributes: attributes || {},
decisionInfo: {
featureKey: featureKey,
featureEnabled: featureEnabled,
variableKey: variableKey,
variableValue: typeCastedValue,
variableType: variableType,
source: decision.decisionSource,
sourceExperimentKey: experimentKey,
sourceVariationKey: variationKey
}
}
);
return typeCastedValue;
};

/**
Expand Down
Loading