Skip to content

Commit 2dc3300

Browse files
committed
Fix test errors related to test data
1 parent 86574b2 commit 2dc3300

2 files changed

Lines changed: 33 additions & 57 deletions

File tree

spec/config/datafile_project_config_spec.rb

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,29 +1602,17 @@
16021602
end
16031603

16041604
describe 'Holdout Decision Reasons' do
1605-
let(:holdout_test_data_path) do
1606-
File.join(File.dirname(__FILE__), 'test_data', 'holdout_test_data.json')
1607-
end
1608-
1609-
let(:holdout_test_data) do
1610-
JSON.parse(File.read(holdout_test_data_path))
1611-
end
1612-
1613-
let(:datafile_with_holdouts) do
1614-
holdout_test_data['datafileWithHoldouts']
1615-
end
1616-
16171605
let(:config_with_holdouts) do
16181606
Optimizely::DatafileProjectConfig.new(
1619-
datafile_with_holdouts,
1607+
OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON,
16201608
logger,
16211609
error_handler
16221610
)
16231611
end
16241612

16251613
describe 'decision reasons structure' do
16261614
it 'should support decision reasons for holdout decisions' do
1627-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1615+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
16281616
expect(feature_flag).not_to be_nil
16291617

16301618
# Verify the feature flag has proper structure for decision reasons
@@ -1710,10 +1698,10 @@
17101698

17111699
describe 'holdout evaluation reasoning' do
17121700
it 'should provide holdout configuration for evaluation' do
1713-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1701+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
17141702
expect(feature_flag).not_to be_nil
17151703

1716-
holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('test_flag_1')
1704+
holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature')
17171705

17181706
holdouts_for_flag.each do |holdout|
17191707
# Each holdout should have necessary info for decision reasoning

spec/decision_service_spec.rb

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,29 +1169,17 @@
11691169
end
11701170

11711171
describe 'Holdout Decision Service Tests' do
1172-
let(:holdout_test_data_path) do
1173-
File.join(File.dirname(__FILE__), 'test_data', 'holdout_test_data.json')
1174-
end
1175-
1176-
let(:holdout_test_data) do
1177-
JSON.parse(File.read(holdout_test_data_path))
1178-
end
1179-
1180-
let(:datafile_with_holdouts) do
1181-
holdout_test_data['datafileWithHoldouts']
1182-
end
1183-
11841172
let(:config_with_holdouts) do
11851173
Optimizely::DatafileProjectConfig.new(
1186-
datafile_with_holdouts,
1174+
OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON,
11871175
spy_logger,
11881176
error_handler
11891177
)
11901178
end
11911179

11921180
let(:project_with_holdouts) do
11931181
Optimizely::Project.new(
1194-
datafile: datafile_with_holdouts,
1182+
datafile: OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON,
11951183
logger: spy_logger,
11961184
error_handler: error_handler
11971185
)
@@ -1208,10 +1196,10 @@
12081196
describe '#get_variations_for_feature_list with holdouts' do
12091197
describe 'when holdout is active and user is bucketed' do
12101198
it 'should return holdout decision with variation' do
1211-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1199+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
12121200
expect(feature_flag).not_to be_nil
12131201

1214-
holdout = config_with_holdouts.get_holdout('holdout_included_1')
1202+
holdout = config_with_holdouts.holdouts.first
12151203
expect(holdout).not_to be_nil
12161204

12171205
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1243,10 +1231,10 @@
12431231

12441232
describe 'when holdout is inactive' do
12451233
it 'should not bucket users and log appropriate message' do
1246-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1234+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
12471235
expect(feature_flag).not_to be_nil
12481236

1249-
holdout = config_with_holdouts.get_holdout('holdout_global_1')
1237+
holdout = config_with_holdouts.holdouts.first
12501238
expect(holdout).not_to be_nil
12511239

12521240
# Mock holdout as inactive
@@ -1275,10 +1263,10 @@
12751263

12761264
describe 'when user is not bucketed into holdout' do
12771265
it 'should execute successfully with valid result structure' do
1278-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1266+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
12791267
expect(feature_flag).not_to be_nil
12801268

1281-
holdout = config_with_holdouts.get_holdout('holdout_included_1')
1269+
holdout = config_with_holdouts.holdouts.first
12821270
expect(holdout).not_to be_nil
12831271

12841272
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1299,10 +1287,10 @@
12991287

13001288
describe 'with user attributes for audience targeting' do
13011289
it 'should evaluate holdout with user attributes' do
1302-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1290+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
13031291
expect(feature_flag).not_to be_nil
13041292

1305-
holdout = config_with_holdouts.get_holdout('holdout_included_1')
1293+
holdout = config_with_holdouts.holdouts.first
13061294
expect(holdout).not_to be_nil
13071295

13081296
user_attributes = {
@@ -1329,7 +1317,7 @@
13291317

13301318
describe 'with multiple holdouts' do
13311319
it 'should handle multiple holdouts for a single feature flag' do
1332-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1320+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
13331321
expect(feature_flag).not_to be_nil
13341322

13351323
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1351,7 +1339,7 @@
13511339

13521340
describe 'with empty user ID' do
13531341
it 'should allow holdout bucketing with empty user ID' do
1354-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1342+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
13551343
expect(feature_flag).not_to be_nil
13561344

13571345
# Empty user ID should still be valid for bucketing
@@ -1376,10 +1364,10 @@
13761364

13771365
describe 'with decision reasons' do
13781366
it 'should populate decision reasons for holdouts' do
1379-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1367+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
13801368
expect(feature_flag).not_to be_nil
13811369

1382-
holdout = config_with_holdouts.get_holdout('holdout_included_1')
1370+
holdout = config_with_holdouts.holdouts.first
13831371
expect(holdout).not_to be_nil
13841372

13851373
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1407,7 +1395,7 @@
14071395
describe '#get_variation_for_feature with holdouts' do
14081396
describe 'when user is bucketed into holdout' do
14091397
it 'should return holdout decision before checking experiments or rollouts' do
1410-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1398+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
14111399
expect(feature_flag).not_to be_nil
14121400

14131401
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1432,7 +1420,7 @@
14321420

14331421
describe 'when holdout returns no decision' do
14341422
it 'should fall through to experiment and rollout evaluation' do
1435-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1423+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
14361424
expect(feature_flag).not_to be_nil
14371425

14381426
# Use a user ID that won't be bucketed into holdout
@@ -1453,7 +1441,7 @@
14531441

14541442
describe 'with decision options' do
14551443
it 'should respect decision options when evaluating holdouts' do
1456-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1444+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
14571445
expect(feature_flag).not_to be_nil
14581446

14591447
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1474,7 +1462,7 @@
14741462

14751463
describe 'holdout priority and evaluation order' do
14761464
it 'should evaluate holdouts before experiments' do
1477-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1465+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
14781466
expect(feature_flag).not_to be_nil
14791467

14801468
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1500,7 +1488,7 @@
15001488
end
15011489

15021490
it 'should evaluate global holdouts for all flags' do
1503-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1491+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
15041492
expect(feature_flag).not_to be_nil
15051493

15061494
# Get global holdouts
@@ -1525,11 +1513,11 @@
15251513

15261514
it 'should respect included and excluded flags configuration' do
15271515
# Test that flags in excludedFlags are not affected by that holdout
1528-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_3']
1516+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
15291517

15301518
if feature_flag
15311519
# Get holdouts for this flag
1532-
holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('test_flag_3')
1520+
holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature')
15331521

15341522
# Should not include holdouts that exclude this flag
15351523
excluded_holdout = holdouts_for_flag.find { |h| h['key'] == 'excluded_holdout' }
@@ -1540,7 +1528,7 @@
15401528

15411529
describe 'holdout logging and error handling' do
15421530
it 'should log when holdout evaluation starts' do
1543-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1531+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
15441532
expect(feature_flag).not_to be_nil
15451533

15461534
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1558,7 +1546,7 @@
15581546
end
15591547

15601548
it 'should handle missing holdout configuration gracefully' do
1561-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1549+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
15621550
expect(feature_flag).not_to be_nil
15631551

15641552
# Temporarily remove holdouts
@@ -1581,7 +1569,7 @@
15811569
end
15821570

15831571
it 'should handle invalid holdout data gracefully' do
1584-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1572+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
15851573
expect(feature_flag).not_to be_nil
15861574

15871575
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1601,7 +1589,7 @@
16011589

16021590
describe 'holdout bucketing behavior' do
16031591
it 'should use consistent bucketing for the same user' do
1604-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1592+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
16051593
expect(feature_flag).not_to be_nil
16061594

16071595
user_id = 'consistent_user'
@@ -1640,7 +1628,7 @@
16401628
end
16411629

16421630
it 'should use bucketing ID when provided' do
1643-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1631+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
16441632
expect(feature_flag).not_to be_nil
16451633

16461634
user_attributes = {
@@ -1663,7 +1651,7 @@
16631651
end
16641652

16651653
it 'should handle different traffic allocations' do
1666-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1654+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
16671655
expect(feature_flag).not_to be_nil
16681656

16691657
# Test with multiple users to see varying bucketing results
@@ -1691,7 +1679,7 @@
16911679

16921680
describe 'holdout integration with feature experiments' do
16931681
it 'should check holdouts before feature experiments' do
1694-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1682+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
16951683
expect(feature_flag).not_to be_nil
16961684

16971685
user_context = project_with_holdouts.create_user_context('testUserId', {})
@@ -1713,7 +1701,7 @@
17131701
end
17141702

17151703
it 'should fall back to experiments if no holdout decision' do
1716-
feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1']
1704+
feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature']
17171705
expect(feature_flag).not_to be_nil
17181706

17191707
user_context = project_with_holdouts.create_user_context('non_holdout_user_123', {})

0 commit comments

Comments
 (0)