|
1250 | 1250 | end |
1251 | 1251 |
|
1252 | 1252 | 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) |
1254 | 1255 | expect(holdouts.length).to eq(3) |
1255 | 1256 |
|
1256 | 1257 | global_holdout = holdouts.find { |h| h['key'] == 'global_holdout' } |
|
1263 | 1264 | end |
1264 | 1265 |
|
1265 | 1266 | 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) |
1267 | 1269 | expect(holdouts.length).to eq(1) |
1268 | 1270 |
|
1269 | 1271 | global_holdout = holdouts.find { |h| h['key'] == 'global_holdout' } |
1270 | 1272 | expect(global_holdout).to be_nil |
1271 | 1273 | end |
1272 | 1274 |
|
1273 | 1275 | 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) |
1276 | 1279 | expect(holdouts1).to equal(holdouts2) |
1277 | 1280 | expect(holdouts1.length).to eq(3) |
1278 | 1281 | end |
1279 | 1282 |
|
1280 | 1283 | 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 = '155557' |
| 1285 | + holdouts = config_with_holdouts.get_holdouts_for_flag(string_feature_id) |
1282 | 1286 |
|
1283 | 1287 | # Should only include global holdout (not excluded and no specific targeting) |
1284 | 1288 | expect(holdouts.length).to eq(2) |
|
1362 | 1366 | # Use the correct feature flag IDs from the debug output |
1363 | 1367 | boolean_feature_id = '155554' |
1364 | 1368 | multi_variate_feature_id = '155559' |
1365 | | - empty_feature_id = '594032' |
1366 | | - string_feature_id = '594060' |
| 1369 | + empty_feature_id = '155564' |
| 1370 | + string_feature_id = '155557' |
1367 | 1371 |
|
1368 | 1372 | config_body_with_holdouts['holdouts'] = [ |
1369 | 1373 | { |
|
1394 | 1398 |
|
1395 | 1399 | it 'should properly categorize holdouts during initialization' do |
1396 | 1400 | 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') |
1398 | 1402 |
|
1399 | 1403 | # Use the correct feature flag IDs |
1400 | 1404 | boolean_feature_id = '155554' |
1401 | 1405 | multi_variate_feature_id = '155559' |
1402 | | - empty_feature_id = '594032' |
1403 | | - string_feature_id = '594060' |
| 1406 | + empty_feature_id = '155564' |
| 1407 | + string_feature_id = '155557' |
1404 | 1408 |
|
1405 | 1409 | expect(config_with_complex_holdouts.included_holdouts[multi_variate_feature_id]).not_to be_nil |
1406 | 1410 | expect(config_with_complex_holdouts.included_holdouts[multi_variate_feature_id]).not_to be_empty |
|
1416 | 1420 |
|
1417 | 1421 | it 'should only process running holdouts during initialization' do |
1418 | 1422 | 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 |
1420 | 1424 |
|
1421 | 1425 | boolean_feature_id = '155554' |
1422 | 1426 | included_for_boolean = config_with_complex_holdouts.included_holdouts[boolean_feature_id] |
|
1470 | 1474 | feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1471 | 1475 | expect(feature_flag).not_to be_nil |
1472 | 1476 |
|
1473 | | - holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
| 1477 | + holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag(feature_flag['id']) |
1474 | 1478 | expect(holdouts_for_flag).to be_an(Array) |
1475 | 1479 | end |
1476 | 1480 | end |
|
1481 | 1485 | feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1482 | 1486 |
|
1483 | 1487 | if feature_flag |
1484 | | - holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
| 1488 | + holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag(feature_flag['id']) |
1485 | 1489 |
|
1486 | 1490 | # Should not include holdouts that exclude this flag |
1487 | 1491 | excluded_holdout = holdouts_for_flag.find { |h| h['key'] == 'excluded_holdout' } |
|
1493 | 1497 | feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1494 | 1498 | expect(feature_flag).not_to be_nil |
1495 | 1499 |
|
1496 | | - holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
| 1500 | + holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag(feature_flag['id']) |
1497 | 1501 | expect(holdouts_for_flag).to be_an(Array) |
1498 | 1502 | end |
1499 | 1503 | end |
|
1519 | 1523 | end |
1520 | 1524 |
|
1521 | 1525 | it 'should properly cache holdout lookups' do |
1522 | | - holdouts_1 = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
1523 | | - holdouts_2 = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
| 1526 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
| 1527 | + holdouts_1 = config_with_holdouts.get_holdouts_for_flag(feature_flag['id']) |
| 1528 | + holdouts_2 = config_with_holdouts.get_holdouts_for_flag(feature_flag['id']) |
1524 | 1529 |
|
1525 | 1530 | expect(holdouts_1).to equal(holdouts_2) |
1526 | 1531 | end |
|
1594 | 1599 |
|
1595 | 1600 | it 'should handle mixed holdout configurations' do |
1596 | 1601 | # Verify the config has properly categorized holdouts |
1597 | | - expect(config_with_holdouts.global_holdouts).to be_a(Hash) |
| 1602 | + expect(config_with_holdouts.global_holdouts).to be_a(Array) |
1598 | 1603 | expect(config_with_holdouts.included_holdouts).to be_a(Hash) |
1599 | 1604 | expect(config_with_holdouts.excluded_holdouts).to be_a(Hash) |
1600 | 1605 | end |
|
1699 | 1704 | feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1700 | 1705 | expect(feature_flag).not_to be_nil |
1701 | 1706 |
|
1702 | | - holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
| 1707 | + holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag(feature_flag['id']) |
1703 | 1708 |
|
1704 | 1709 | holdouts_for_flag.each do |holdout| |
1705 | 1710 | # Each holdout should have necessary info for decision reasoning |
|
1754 | 1759 | error_handler |
1755 | 1760 | ) |
1756 | 1761 |
|
1757 | | - holdouts_for_flag = config_without_holdouts.get_holdouts_for_flag('boolean_feature') |
| 1762 | + feature_flag = config_without_holdouts.feature_flag_key_map['boolean_feature'] |
| 1763 | + holdouts_for_flag = config_without_holdouts.get_holdouts_for_flag(feature_flag['id']) |
1758 | 1764 | expect(holdouts_for_flag).to eq([]) |
1759 | 1765 | end |
1760 | 1766 |
|
|
1774 | 1780 | config = Optimizely::DatafileProjectConfig.new(config_json, logger, error_handler) |
1775 | 1781 |
|
1776 | 1782 | # Should treat as global holdout |
1777 | | - expect(config.global_holdouts['holdout_nil']).not_to be_nil |
| 1783 | + expect(config.global_holdouts.find { |h| h['id'] == 'holdout_nil' }).not_to be_nil |
1778 | 1784 | end |
1779 | 1785 |
|
1780 | 1786 | it 'should only include running holdouts in maps' do |
|
0 commit comments