Skip to content

feat(api): Feature variable APIs return default variable value when featureEnabled property is false. #162

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 3 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion lib/optimizely.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def get_feature_variable_for_type(feature_flag_key, variable_key, variable_type,
variation = decision['variation']
variation_variable_usages = @config.variation_id_to_variable_usage_map[variation['id']]
variable_id = variable['id']
if variation_variable_usages&.key?(variable_id)
if variation['featureEnabled'] && variation_variable_usages&.key?(variable_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the log message in the else clause is incorrect for this new scenario. It should be the log message in the else clause for decision (above). Please update accordingly.

variable_value = variation_variable_usages[variable_id]['value']
@logger.log(Logger::INFO,
"Got variable value '#{variable_value}' for variable '#{variable_key}' of feature flag '#{feature_flag_key}'.")
Expand Down
47 changes: 47 additions & 0 deletions spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,53 @@ class InvalidErrorHandler; end
end
end

describe '#get_feature_variable_for_type with default variables' do
it 'should return default variable type and value, when user in experiment and feature is not enabled' do
integer_feature = project_instance.config.feature_flag_key_map['integer_single_variable_feature']
experiment_to_return = project_instance.config.experiment_id_map[integer_feature['experimentIds'][0]]
variation_to_return = experiment_to_return['variations'][0]
variation_to_return['featureEnabled'] = false
decision_to_return = Optimizely::DecisionService::Decision.new(
experiment_to_return,
variation_to_return,
Optimizely::DecisionService::DECISION_SOURCE_EXPERIMENT
)

allow(project_instance.decision_service).to receive(:get_variation_for_feature).and_return(decision_to_return)

expect(project_instance.send(
:get_feature_variable_for_type,
'integer_single_variable_feature',
'integer_variable',
'integer',
'test_user',
'browser_type' => 'firefox'
)).to eq(7)
end

it 'should return default variable type and value, when user in rollout and feature is not enabled' do
experiment_to_return = config_body['rollouts'][0]['experiments'][1]
variation_to_return = experiment_to_return['variations'][0]
decision_to_return = Optimizely::DecisionService::Decision.new(
experiment_to_return,
variation_to_return,
Optimizely::DecisionService::DECISION_SOURCE_ROLLOUT
)
allow(project_instance.decision_service).to receive(:get_variation_for_feature).and_return(decision_to_return)

expect(variation_to_return['featureEnabled']).to be false

expect(project_instance.send(
:get_feature_variable_for_type,
'boolean_single_variable_feature',
'boolean_variable',
'boolean',
'test_user',
{}
)).to eq(true)
end
end

describe 'when forced variation is used' do
# setForcedVariation on a paused experiment and then call getVariation.
it 'should return null when getVariation is called on a paused experiment after setForcedVariation' do
Expand Down