Skip to content

Commit 8108c73

Browse files
committed
Fix unit tests
1 parent 9b513f2 commit 8108c73

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/optimizely/config/datafile_project_config.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def initialize(datafile, logger, error_handler)
123123
@holdouts.each do |holdout|
124124
next unless holdout['status'] == 'Running'
125125

126+
# Ensure holdout has layerId field (holdouts don't have campaigns)
127+
holdout['layerId'] ||= ''
128+
126129
@holdout_id_map[holdout['id']] = holdout
127130

128131
included_flags = holdout['includedFlags'] || []

spec/config/datafile_project_config_spec.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,8 @@
12501250
end
12511251

12521252
it 'should return global holdouts that do not exclude the flag' do
1253-
holdouts = config_with_holdouts.get_holdouts_for_flag('multi_variate_feature')
1253+
multi_variate_feature_id = '155559'
1254+
holdouts = config_with_holdouts.get_holdouts_for_flag(multi_variate_feature_id)
12541255
expect(holdouts.length).to eq(3)
12551256

12561257
global_holdout = holdouts.find { |h| h['key'] == 'global_holdout' }
@@ -1263,22 +1264,25 @@
12631264
end
12641265

12651266
it 'should not return global holdouts that exclude the flag' do
1266-
holdouts = config_with_holdouts.get_holdouts_for_flag('boolean_single_variable_feature')
1267+
boolean_feature_id = '155554'
1268+
holdouts = config_with_holdouts.get_holdouts_for_flag(boolean_feature_id)
12671269
expect(holdouts.length).to eq(1)
12681270

12691271
global_holdout = holdouts.find { |h| h['key'] == 'global_holdout' }
12701272
expect(global_holdout).to be_nil
12711273
end
12721274

12731275
it 'should cache results for subsequent calls' do
1274-
holdouts1 = config_with_holdouts.get_holdouts_for_flag('multi_variate_feature')
1275-
holdouts2 = config_with_holdouts.get_holdouts_for_flag('multi_variate_feature')
1276+
multi_variate_feature_id = '155559'
1277+
holdouts1 = config_with_holdouts.get_holdouts_for_flag(multi_variate_feature_id)
1278+
holdouts2 = config_with_holdouts.get_holdouts_for_flag(multi_variate_feature_id)
12761279
expect(holdouts1).to equal(holdouts2)
12771280
expect(holdouts1.length).to eq(3)
12781281
end
12791282

12801283
it 'should return only global holdouts for flags not specifically targeted' do
1281-
holdouts = config_with_holdouts.get_holdouts_for_flag('string_single_variable_feature')
1284+
string_feature_id = '594060'
1285+
holdouts = config_with_holdouts.get_holdouts_for_flag(string_feature_id)
12821286

12831287
# Should only include global holdout (not excluded and no specific targeting)
12841288
expect(holdouts.length).to eq(2)
@@ -1394,7 +1398,7 @@
13941398

13951399
it 'should properly categorize holdouts during initialization' do
13961400
expect(config_with_complex_holdouts.holdout_id_map.keys).to contain_exactly('global_holdout', 'specific_holdout')
1397-
expect(config_with_complex_holdouts.global_holdouts.keys).to contain_exactly('global_holdout')
1401+
expect(config_with_complex_holdouts.global_holdouts.map { |h| h['id'] }).to contain_exactly('global_holdout')
13981402

13991403
# Use the correct feature flag IDs
14001404
boolean_feature_id = '155554'
@@ -1416,7 +1420,7 @@
14161420

14171421
it 'should only process running holdouts during initialization' do
14181422
expect(config_with_complex_holdouts.holdout_id_map['inactive_holdout']).to be_nil
1419-
expect(config_with_complex_holdouts.global_holdouts['inactive_holdout']).to be_nil
1423+
expect(config_with_complex_holdouts.global_holdouts.find { |h| h['id'] == 'inactive_holdout' }).to be_nil
14201424

14211425
boolean_feature_id = '155554'
14221426
included_for_boolean = config_with_complex_holdouts.included_holdouts[boolean_feature_id]
@@ -1594,7 +1598,7 @@
15941598

15951599
it 'should handle mixed holdout configurations' do
15961600
# Verify the config has properly categorized holdouts
1597-
expect(config_with_holdouts.global_holdouts).to be_a(Hash)
1601+
expect(config_with_holdouts.global_holdouts).to be_a(Array)
15981602
expect(config_with_holdouts.included_holdouts).to be_a(Hash)
15991603
expect(config_with_holdouts.excluded_holdouts).to be_a(Hash)
16001604
end
@@ -1774,7 +1778,7 @@
17741778
config = Optimizely::DatafileProjectConfig.new(config_json, logger, error_handler)
17751779

17761780
# Should treat as global holdout
1777-
expect(config.global_holdouts['holdout_nil']).not_to be_nil
1781+
expect(config.global_holdouts.find { |h| h['id'] == 'holdout_nil' }).not_to be_nil
17781782
end
17791783

17801784
it 'should only include running holdouts in maps' do

0 commit comments

Comments
 (0)