|
364 | 364 |
|
365 | 365 | expect(decision_result).not_to be_nil |
366 | 366 |
|
367 | | - decision_result.decision && decision_result.decision.source == Optimizely::DecisionService::DECISION_SOURCES['HOLDOUT'] && holdout_decisions << decision_result |
368 | | - expect(decision_service_with_holdouts).not_to have_received(:get_variation_for_feature_experiment) |
| 367 | + expect(decision_service_with_holdouts).not_to have_received(:get_variation_for_feature_experiment) if decision_result.decision && decision_result.decision.source == Optimizely::DecisionService::DECISION_SOURCES['HOLDOUT'] |
369 | 368 | end |
370 | 369 |
|
371 | 370 | it 'should evaluate global holdouts for all flags' do |
|
710 | 709 | notification_callback |
711 | 710 | ) |
712 | 711 |
|
713 | | - # Mock the decision service to return a holdout decision |
| 712 | + test_user_id = 'holdout_test_user' |
| 713 | + feature_flag = config_with_holdouts.feature_flag_key_map['boolean_feature'] |
714 | 714 | holdout = config_with_holdouts.holdouts.first |
715 | 715 | expect(holdout).not_to be_nil, 'Should have at least one holdout configured' |
716 | 716 |
|
717 | 717 | holdout_variation = holdout['variations'].first |
718 | 718 | expect(holdout_variation).not_to be_nil, 'Holdout should have at least one variation' |
719 | 719 |
|
720 | | - # Create a holdout decision |
| 720 | + # Mock the decision service to return a holdout decision |
721 | 721 | holdout_decision = Optimizely::DecisionService::Decision.new( |
722 | 722 | holdout, |
723 | 723 | holdout_variation, |
|
730 | 730 | [] |
731 | 731 | ) |
732 | 732 |
|
733 | | - # Mock get_variations_for_feature_list to return holdout decision |
734 | | - allow_any_instance_of(Optimizely::DecisionService).to receive(:get_variations_for_feature_list) |
| 733 | + # Mock get_variations_for_feature_list instead of get_variation_for_feature |
| 734 | + allow(optimizely_with_mocked_events.decision_service).to receive(:get_variations_for_feature_list) |
735 | 735 | .and_return([holdout_decision_result]) |
736 | 736 |
|
737 | | - test_user_id = 'test_user' |
738 | | - user_attributes = {'country' => 'us'} |
739 | | - |
740 | | - _user_context = optimizely_with_mocked_events.create_user_context(test_user_id, user_attributes) |
| 737 | + user_context = optimizely_with_mocked_events.create_user_context(test_user_id, {}) |
| 738 | + decision = user_context.decide(feature_flag['key']) |
741 | 739 |
|
| 740 | + expect(decision).not_to be_nil, 'Decision should not be nil' |
742 | 741 | expect(captured_notifications.length).to eq(1), 'Should have captured exactly one decision notification' |
743 | 742 |
|
744 | 743 | notification = captured_notifications.first |
|
0 commit comments