|
1425 | 1425 | end |
1426 | 1426 |
|
1427 | 1427 | describe 'Holdout Decision Functionality' do |
1428 | | - let(:holdout_test_data_path) do |
1429 | | - File.join(File.dirname(__FILE__), 'test_data', 'holdout_test_data.json') |
1430 | | - end |
1431 | | - |
1432 | | - let(:holdout_test_data) do |
1433 | | - JSON.parse(File.read(holdout_test_data_path)) |
1434 | | - end |
1435 | | - |
1436 | | - let(:datafile_with_holdouts) do |
1437 | | - holdout_test_data['datafileWithHoldouts'] |
1438 | | - end |
1439 | | - |
1440 | 1428 | let(:config_with_holdouts) do |
1441 | 1429 | Optimizely::DatafileProjectConfig.new( |
1442 | | - datafile_with_holdouts, |
| 1430 | + OptimizelySpec::CONFIG_BODY_WITH_HOLDOUTS_JSON, |
1443 | 1431 | logger, |
1444 | 1432 | error_handler |
1445 | 1433 | ) |
1446 | 1434 | end |
1447 | 1435 |
|
1448 | 1436 | describe '#decide with global holdout' do |
1449 | 1437 | it 'should return valid decision for global holdout' do |
1450 | | - feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1'] |
| 1438 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1451 | 1439 | expect(feature_flag).not_to be_nil |
1452 | 1440 |
|
1453 | 1441 | # Verify holdouts are loaded |
|
1456 | 1444 | end |
1457 | 1445 |
|
1458 | 1446 | it 'should handle decision with global holdout configuration' do |
1459 | | - feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1'] |
| 1447 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1460 | 1448 | expect(feature_flag).not_to be_nil |
1461 | 1449 | expect(feature_flag['id']).not_to be_empty |
1462 | 1450 | end |
1463 | 1451 | end |
1464 | 1452 |
|
1465 | 1453 | describe '#decide with included flags holdout' do |
1466 | 1454 | it 'should return valid decision for included flags' do |
1467 | | - feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1'] |
| 1455 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1468 | 1456 | expect(feature_flag).not_to be_nil |
1469 | 1457 |
|
1470 | 1458 | # Check if there's a holdout that includes this flag |
|
1479 | 1467 | end |
1480 | 1468 |
|
1481 | 1469 | it 'should properly filter holdouts based on includedFlags' do |
1482 | | - feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1'] |
| 1470 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1483 | 1471 | expect(feature_flag).not_to be_nil |
1484 | 1472 |
|
1485 | | - holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('test_flag_1') |
| 1473 | + holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
1486 | 1474 | expect(holdouts_for_flag).to be_an(Array) |
1487 | 1475 | end |
1488 | 1476 | end |
1489 | 1477 |
|
1490 | 1478 | describe '#decide with excluded flags holdout' do |
1491 | 1479 | it 'should not return excluded holdout for excluded flag' do |
1492 | | - # test_flag_3 is excluded by holdout_excluded_1 |
1493 | | - feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_3'] |
| 1480 | + # boolean_feature is excluded by holdout_excluded_1 |
| 1481 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1494 | 1482 |
|
1495 | 1483 | if feature_flag |
1496 | | - holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('test_flag_3') |
| 1484 | + holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
1497 | 1485 |
|
1498 | 1486 | # Should not include holdouts that exclude this flag |
1499 | 1487 | excluded_holdout = holdouts_for_flag.find { |h| h['key'] == 'excluded_holdout' } |
|
1502 | 1490 | end |
1503 | 1491 |
|
1504 | 1492 | it 'should return holdouts for non-excluded flag' do |
1505 | | - feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1'] |
| 1493 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1506 | 1494 | expect(feature_flag).not_to be_nil |
1507 | 1495 |
|
1508 | | - holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('test_flag_1') |
| 1496 | + holdouts_for_flag = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
1509 | 1497 | expect(holdouts_for_flag).to be_an(Array) |
1510 | 1498 | end |
1511 | 1499 | end |
1512 | 1500 |
|
1513 | 1501 | describe '#decide with multiple holdouts' do |
1514 | 1502 | it 'should handle multiple holdouts for different flags' do |
1515 | | - flag_keys = %w[test_flag_1 test_flag_2 test_flag_3 test_flag_4] |
| 1503 | + flag_keys = %w[boolean_feature multi_variate_feature string_single_variable_feature empty_feature] |
1516 | 1504 |
|
1517 | 1505 | flag_keys.each do |flag_key| |
1518 | 1506 | feature_flag = config_with_holdouts.feature_flag_key_map[flag_key] |
|
1531 | 1519 | end |
1532 | 1520 |
|
1533 | 1521 | it 'should properly cache holdout lookups' do |
1534 | | - holdouts_1 = config_with_holdouts.get_holdouts_for_flag('test_flag_1') |
1535 | | - holdouts_2 = config_with_holdouts.get_holdouts_for_flag('test_flag_1') |
| 1522 | + holdouts_1 = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
| 1523 | + holdouts_2 = config_with_holdouts.get_holdouts_for_flag('boolean_feature') |
1536 | 1524 |
|
1537 | 1525 | expect(holdouts_1).to equal(holdouts_2) |
1538 | 1526 | end |
|
1566 | 1554 |
|
1567 | 1555 | describe '#decide with empty user id' do |
1568 | 1556 | it 'should handle empty user id without error' do |
1569 | | - feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1'] |
| 1557 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1570 | 1558 | expect(feature_flag).not_to be_nil |
1571 | 1559 |
|
1572 | 1560 | # Empty user ID should be valid for bucketing |
1573 | 1561 | # This test verifies the config structure supports this |
1574 | | - expect(feature_flag['key']).to eq('test_flag_1') |
| 1562 | + expect(feature_flag['key']).to eq('boolean_feature') |
1575 | 1563 | end |
1576 | 1564 | end |
1577 | 1565 |
|
1578 | 1566 | describe '#holdout priority evaluation' do |
1579 | 1567 | it 'should evaluate global holdouts for flags without specific targeting' do |
1580 | | - feature_flag = config_with_holdouts.feature_flag_key_map['test_flag_1'] |
| 1568 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
1581 | 1569 | expect(feature_flag).not_to be_nil |
1582 | 1570 |
|
1583 | 1571 | global_holdouts = config_with_holdouts.holdouts.select do |h| |
|
0 commit comments