Skip to content

Commit 9425dd2

Browse files
[AI-FSSDK] [FSSDK-12337] Add tests for featureEnabled and variables propagation
Add tests verifying: - Injected everyone-else variation preserves featureEnabled=false - Variables from the rollout variation carry through to the injected variation and populate variation_id_to_variable_usage_map
1 parent deda391 commit 9425dd2

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

spec/config/datafile_project_config_spec.rb

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,5 +2178,127 @@ def build_datafile(experiments: [], rollouts: [], feature_flags: [])
21782178
expect(variation_ids).not_to include('targeted_var_1')
21792179
expect(variation_ids).not_to include('targeted_var_2')
21802180
end
2181+
2182+
it 'should preserve featureEnabled value on injected variation' do
2183+
datafile = build_datafile(
2184+
experiments: [
2185+
{
2186+
'id' => 'exp_fr',
2187+
'key' => 'feature_rollout_exp',
2188+
'status' => 'Running',
2189+
'forcedVariations' => {},
2190+
'layerId' => 'layer_1',
2191+
'audienceIds' => [],
2192+
'trafficAllocation' => [{'entityId' => 'rollout_var', 'endOfRange' => 5000}],
2193+
'variations' => [
2194+
{'key' => 'rollout_var', 'id' => 'rollout_var', 'featureEnabled' => true}
2195+
],
2196+
'type' => 'feature_rollout'
2197+
}
2198+
],
2199+
rollouts: [
2200+
{
2201+
'id' => 'rollout_1',
2202+
'experiments' => [
2203+
{
2204+
'id' => 'rollout_everyone_else',
2205+
'key' => 'rollout_everyone_else',
2206+
'status' => 'Running',
2207+
'forcedVariations' => {},
2208+
'layerId' => 'rollout_1',
2209+
'audienceIds' => [],
2210+
'trafficAllocation' => [{'entityId' => 'everyone_else_var', 'endOfRange' => 10_000}],
2211+
'variations' => [
2212+
{'key' => 'everyone_else_var', 'id' => 'everyone_else_var', 'featureEnabled' => false}
2213+
]
2214+
}
2215+
]
2216+
}
2217+
],
2218+
feature_flags: [
2219+
{
2220+
'id' => 'flag_1',
2221+
'key' => 'test_flag',
2222+
'experimentIds' => ['exp_fr'],
2223+
'rolloutId' => 'rollout_1',
2224+
'variables' => []
2225+
}
2226+
]
2227+
)
2228+
2229+
config = Optimizely::DatafileProjectConfig.new(JSON.dump(datafile), logger, error_handler)
2230+
experiment = config.experiment_id_map['exp_fr']
2231+
2232+
injected = experiment['variations'].find { |v| v['id'] == 'everyone_else_var' }
2233+
expect(injected).not_to be_nil
2234+
expect(injected['featureEnabled']).to eq(false)
2235+
end
2236+
2237+
it 'should propagate variables from the everyone else variation' do
2238+
datafile = build_datafile(
2239+
experiments: [
2240+
{
2241+
'id' => 'exp_fr',
2242+
'key' => 'feature_rollout_exp',
2243+
'status' => 'Running',
2244+
'forcedVariations' => {},
2245+
'layerId' => 'layer_1',
2246+
'audienceIds' => [],
2247+
'trafficAllocation' => [{'entityId' => 'rollout_var', 'endOfRange' => 5000}],
2248+
'variations' => [
2249+
{'key' => 'rollout_var', 'id' => 'rollout_var', 'featureEnabled' => true}
2250+
],
2251+
'type' => 'feature_rollout'
2252+
}
2253+
],
2254+
rollouts: [
2255+
{
2256+
'id' => 'rollout_1',
2257+
'experiments' => [
2258+
{
2259+
'id' => 'rollout_everyone_else',
2260+
'key' => 'rollout_everyone_else',
2261+
'status' => 'Running',
2262+
'forcedVariations' => {},
2263+
'layerId' => 'rollout_1',
2264+
'audienceIds' => [],
2265+
'trafficAllocation' => [{'entityId' => 'everyone_else_var', 'endOfRange' => 10_000}],
2266+
'variations' => [
2267+
{
2268+
'key' => 'everyone_else_var',
2269+
'id' => 'everyone_else_var',
2270+
'featureEnabled' => false,
2271+
'variables' => [
2272+
{'id' => 'var_1', 'value' => 'default_value'}
2273+
]
2274+
}
2275+
]
2276+
}
2277+
]
2278+
}
2279+
],
2280+
feature_flags: [
2281+
{
2282+
'id' => 'flag_1',
2283+
'key' => 'test_flag',
2284+
'experimentIds' => ['exp_fr'],
2285+
'rolloutId' => 'rollout_1',
2286+
'variables' => []
2287+
}
2288+
]
2289+
)
2290+
2291+
config = Optimizely::DatafileProjectConfig.new(JSON.dump(datafile), logger, error_handler)
2292+
experiment = config.experiment_id_map['exp_fr']
2293+
2294+
injected = experiment['variations'].find { |v| v['id'] == 'everyone_else_var' }
2295+
expect(injected).not_to be_nil
2296+
expect(injected['variables']).to eq([{'id' => 'var_1', 'value' => 'default_value'}])
2297+
2298+
# Verify variation_id_to_variable_usage_map is populated
2299+
variable_usage = config.variation_id_to_variable_usage_map['everyone_else_var']
2300+
expect(variable_usage).not_to be_nil
2301+
expect(variable_usage).to have_key('var_1')
2302+
end
21812303
end
21822304
end

0 commit comments

Comments
 (0)