Skip to content

feat: Added a new getAllFeatureVariables Api #470

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 10 commits into from
May 6, 2020

Conversation

zashraf1985
Copy link
Contributor

Summary

Implemented getAllFeatureVariables API

Test plan

Added new unit tests.

@zashraf1985 zashraf1985 removed their assignment May 1, 2020
@@ -957,6 +957,127 @@ Optimizely.prototype.getFeatureVariableJson = function(featureKey, variableKey,
}
};

/**
* Returns values for all the json variables attached to the given feature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns all variable values, not just values for JSON variables, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It was a copy/paste mistake.

var variableValue = variable.defaultValue;
if (decision.variation !== null) {
var value = projectConfig.getVariableValueForVariation(configObj, variable, decision.variation, logger);
if (value !== null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you are following _getFeatureVariableForType, can we refactor & call that from here instead of duplicating this logic?

Aside, reading this now I find it a little hard to follow with the nested ifs. Can we flatten this out while preserving the same behavior? decision.variation !== null, value !== null, featureEnabled determine the log message. decision.variation !== null and featureEnabled determine the variable value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. since i dont understand all the behaviour in detail, i followed whatever was already there. The tests already written are extremely thorough. I will go ahead and simplify the stuff and rely on the tests to ensure correctness

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjc1283 I refactored this.

  1. Moved common code in a separate function
  2. Separated logs logic and variable assignment.
  3. Simplified checks for logs to make them more readable and added comments

Copy link

@pawels-optimizely pawels-optimizely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content of the tests is good, I agree with @mjc1283 comments

@zashraf1985 zashraf1985 removed their assignment May 2, 2020
@@ -89,6 +89,17 @@ declare module '@optimizely/optimizely-sdk' {
userId: string,
attributes?: UserAttributes
): string | null;
getFeatureVariableJson(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Good catch updating this! Let's use unknown for the return value of these, instead of any.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one request

if (decision.variation !== null) {
featureEnabled = decision.variation.featureEnabled;
var value = projectConfig.getVariableValueForVariation(configObj, variable, decision.variation, this.logger);
Optimizely.prototype._getFeatureVariableValueFromVariation = function(featureKey, featureEnabled, variation, variable, userId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a doc comment for _getFeatureVariableValueFromVariation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@mjc1283 mjc1283 merged commit 146fb43 into master May 6, 2020
@mjc1283 mjc1283 deleted the zeeshan/get-all-feature-variables branch May 6, 2020 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants