Skip to content

Commit

Permalink
fix(is_feature_enabled): Added rollout experiment key map for onboard…
Browse files Browse the repository at this point in the history
…ing datafile (#168)
  • Loading branch information
rashidsp authored and Michael Ng committed May 17, 2019
1 parent 486357d commit 22eafd6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/optimizely/project_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ProjectConfig
attr_reader :feature_variable_key_map
attr_reader :group_key_map
attr_reader :rollout_id_map
attr_reader :rollout_experiment_id_map
attr_reader :rollout_experiment_key_map
attr_reader :variation_id_map
attr_reader :variation_id_to_variable_usage_map
attr_reader :variation_key_map
Expand Down Expand Up @@ -120,13 +120,13 @@ def initialize(datafile, logger, error_handler)
end
end
@rollout_id_map = generate_key_map(@rollouts, 'id')
# split out the experiment id map for rollouts
@rollout_experiment_id_map = {}
# split out the experiment key map for rollouts
@rollout_experiment_key_map = {}
@rollout_id_map.each_value do |rollout|
exps = rollout.fetch('experiments')
@rollout_experiment_id_map = @rollout_experiment_id_map.merge(generate_key_map(exps, 'id'))
@rollout_experiment_key_map = @rollout_experiment_key_map.merge(generate_key_map(exps, 'key'))
end
@all_experiments = @experiment_key_map.merge(@rollout_experiment_id_map)
@all_experiments = @experiment_key_map.merge(@rollout_experiment_key_map)
@all_experiments.each do |key, exp|
variations = exp.fetch('variations')
variations.each do |variation|
Expand Down
26 changes: 22 additions & 4 deletions spec/project_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@
feature_enabled => true,
'variables' => []
}
},
'rollout_exp_with_diff_id_and_key' => {
'177781' => {
'id' => '177781',
'key' => 'rollout_var_with_diff_id_and_key',
feature_enabled => true,
'variables' => []
}
}
}

Expand Down Expand Up @@ -448,6 +456,14 @@
feature_enabled => true,
'variables' => []
}
},
'rollout_exp_with_diff_id_and_key' => {
'rollout_var_with_diff_id_and_key' => {
'id' => '177781',
'key' => 'rollout_var_with_diff_id_and_key',
feature_enabled => true,
'variables' => []
}
}
}

Expand Down Expand Up @@ -641,20 +657,22 @@
'value' => 'false'
}
},
'177780' => {}
'177780' => {},
'177781' => {}
}

expected_rollout_id_map = {
'166660' => config_body['rollouts'][0],
'166661' => config_body['rollouts'][1]
}

expected_rollout_experiment_id_map = {
expected_rollout_experiment_key_map = {
'177770' => config_body['rollouts'][0]['experiments'][0],
'177772' => config_body['rollouts'][0]['experiments'][1],
'177776' => config_body['rollouts'][0]['experiments'][2],
'177774' => config_body['rollouts'][1]['experiments'][0],
'177779' => config_body['rollouts'][1]['experiments'][1]
'177779' => config_body['rollouts'][1]['experiments'][1],
'rollout_exp_with_diff_id_and_key' => config_body['rollouts'][1]['experiments'][2]
}

expect(project_config.attribute_key_map).to eq(expected_attribute_key_map)
Expand All @@ -668,7 +686,7 @@
expect(project_config.variation_key_map).to eq(expected_variation_key_map)
expect(project_config.variation_id_to_variable_usage_map).to eq(expected_variation_id_to_variable_usage_map)
expect(project_config.rollout_id_map).to eq(expected_rollout_id_map)
expect(project_config.rollout_experiment_id_map).to eq(expected_rollout_experiment_id_map)
expect(project_config.rollout_experiment_key_map).to eq(expected_rollout_experiment_key_map)
end

it 'should initialize properties correctly upon creating project with typed audience dict' do
Expand Down
16 changes: 16 additions & 0 deletions spec/spec_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,22 @@ module OptimizelySpec
'entityId' => '177780',
'endOfRange' => 1500
}]
}, {
'id' => '177780',
'key' => 'rollout_exp_with_diff_id_and_key',
'status' => 'Running',
'layerId' => '166661',
'audienceIds' => [],
'variations' => [{
'id' => '177781',
'key' => 'rollout_var_with_diff_id_and_key',
'featureEnabled' => true,
'variables' => []
}],
'trafficAllocation' => [{
'entityId' => '177781',
'endOfRange' => 1500
}]
}]
}]
}.freeze
Expand Down

0 comments on commit 22eafd6

Please sign in to comment.