@@ -592,11 +592,17 @@ class InvalidErrorHandler; end
592592 . with ( 'test_experiment' )
593593 . and_return ( [ ] )
594594 experiment = project_instance . config . get_experiment_from_key ( 'test_experiment' )
595+
596+ # Decision listener
597+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . ordered
598+
599+ # Activate listener
595600 expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
596601 Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ,
597602 experiment , 'test_user' , nil , variation_to_return ,
598603 instance_of ( Optimizely ::Event )
599- )
604+ ) . ordered
605+
600606 project_instance . activate ( 'test_experiment' , 'test_user' )
601607
602608 expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::INFO , include ( 'Dispatching impression event to' \
@@ -649,6 +655,36 @@ class InvalidErrorHandler; end
649655 invalid_project = Optimizely ::Project . new ( 'invalid' )
650656 invalid_project . activate ( 'test_exp' , 'test_user' )
651657 end
658+
659+ describe '.decision listener' do
660+ it 'should call decision listener when user not in experiment' do
661+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
662+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
663+ 'experiment' , 'test_user' , { } ,
664+ experiment_key : 'test_experiment_with_audience' , variation_key : nil
665+ )
666+
667+ project_instance . activate ( 'test_experiment_with_audience' , 'test_user' )
668+ end
669+
670+ it 'should call decision listener when user in experiment' do
671+ variation_to_return = project_instance . config . get_variation_from_id ( 'test_experiment' , '111128' )
672+ allow ( project_instance . decision_service . bucketer ) . to receive ( :bucket ) . and_return ( variation_to_return )
673+ expect ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
674+
675+ # Decision listener
676+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
677+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
678+ 'experiment' , 'test_user' , { } ,
679+ experiment_key : 'test_experiment' , variation_key : 'control'
680+ ) . ordered
681+
682+ # Activate listener
683+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . ordered
684+
685+ project_instance . activate ( 'test_experiment' , 'test_user' )
686+ end
687+ end
652688 end
653689
654690 describe '#track' do
@@ -1066,6 +1102,28 @@ class InvalidErrorHandler; end
10661102 invalid_project = Optimizely ::Project . new ( 'invalid' )
10671103 invalid_project . get_variation ( 'test_exp' , 'test_user' )
10681104 end
1105+
1106+ describe '.decision listener' do
1107+ it 'should call decision listener when user in experiment' do
1108+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
1109+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
1110+ 'experiment' , 'test_user' , { 'browser_type' => 'firefox' } ,
1111+ experiment_key : 'test_experiment_with_audience' , variation_key : 'control_with_audience'
1112+ )
1113+
1114+ project_instance . get_variation ( 'test_experiment_with_audience' , 'test_user' , 'browser_type' => 'firefox' )
1115+ end
1116+
1117+ it 'should call decision listener when user not in experiment' do
1118+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
1119+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] ,
1120+ 'experiment' , 'test_user' , { 'browser_type' => 'chrome' } ,
1121+ experiment_key : 'test_experiment_with_audience' , variation_key : nil
1122+ )
1123+
1124+ project_instance . get_variation ( 'test_experiment_with_audience' , 'test_user' , 'browser_type' => 'chrome' )
1125+ end
1126+ end
10691127 end
10701128
10711129 describe '#is_feature_enabled' do
0 commit comments