@@ -587,6 +587,11 @@ class InvalidErrorHandler; end
587587 end
588588
589589 it 'should log and send activate notification when an impression event is dispatched' do
590+ def callback ( _args ) ; end
591+ project_instance . notification_center . add_notification_listener (
592+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ,
593+ method ( :callback )
594+ )
590595 variation_to_return = project_instance . config_manager . config . get_variation_from_id ( 'test_experiment' , '111128' )
591596 allow ( project_instance . decision_service . bucketer ) . to receive ( :bucket ) . and_return ( variation_to_return )
592597 allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
@@ -600,6 +605,11 @@ class InvalidErrorHandler; end
600605 Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :DECISION ] , any_args
601606 ) . ordered
602607
608+ # Log event
609+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
610+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :LOG_EVENT ] , any_args
611+ ) . ordered
612+
603613 # Activate listener
604614 expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . with (
605615 Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ,
@@ -886,13 +896,26 @@ class InvalidErrorHandler; end
886896 params = @expected_track_event_params
887897 params [ :visitors ] [ 0 ] [ :snapshots ] [ 0 ] [ :events ] [ 0 ] . merge! ( revenue : 42 ,
888898 tags : { 'revenue' => 42 } )
899+
900+ def callback ( _args ) ; end
901+ project_instance . notification_center . add_notification_listener (
902+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :TRACK ] ,
903+ method ( :callback )
904+ )
889905 allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
890906 conversion_event = Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers )
907+
908+ expect ( project_instance . notification_center ) . to receive ( :send_notifications )
909+ . with (
910+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :LOG_EVENT ] , any_args
911+ ) . ordered
912+
891913 expect ( project_instance . notification_center ) . to receive ( :send_notifications )
892914 . with (
893915 Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :TRACK ] ,
894916 'test_event' , 'test_user' , nil , { 'revenue' => 42 } , conversion_event
895- ) . once
917+ ) . ordered
918+
896919 project_instance . track ( 'test_event' , 'test_user' , nil , 'revenue' => 42 )
897920 expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
898921 end
@@ -1463,6 +1486,12 @@ class InvalidErrorHandler; end
14631486 end
14641487
14651488 it 'should return true, send activate notification and an impression if the user is bucketed into a feature experiment' do
1489+ def callback ( _args ) ; end
1490+ project_instance . notification_center . add_notification_listener (
1491+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ,
1492+ method ( :callback )
1493+ )
1494+
14661495 allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
14671496 experiment_to_return = config_body [ 'experiments' ] [ 3 ]
14681497 variation_to_return = experiment_to_return [ 'variations' ] [ 0 ]
@@ -1472,6 +1501,11 @@ class InvalidErrorHandler; end
14721501 Optimizely ::DecisionService ::DECISION_SOURCES [ 'FEATURE_TEST' ]
14731502 )
14741503
1504+ expect ( project_instance . notification_center ) . to receive ( :send_notifications )
1505+ . with (
1506+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :LOG_EVENT ] , any_args
1507+ ) . ordered
1508+
14751509 expect ( project_instance . notification_center ) . to receive ( :send_notifications )
14761510 . with (
14771511 Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ,
@@ -1709,6 +1743,12 @@ class InvalidErrorHandler; end
17091743
17101744 describe '.decision listener' do
17111745 it 'should return enabled features and call decision listener for all features' do
1746+ def callback ( _args ) ; end
1747+ project_instance . notification_center . add_notification_listener (
1748+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ,
1749+ method ( :callback )
1750+ )
1751+
17121752 allow ( project_instance . event_dispatcher ) . to receive ( :dispatch_event ) . with ( instance_of ( Optimizely ::Event ) )
17131753
17141754 enabled_features = %w[ boolean_feature integer_single_variable_feature ]
@@ -1739,6 +1779,10 @@ class InvalidErrorHandler; end
17391779 nil
17401780 )
17411781
1782+ expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . twice . with (
1783+ Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :LOG_EVENT ] , any_args
1784+ )
1785+
17421786 expect ( project_instance . notification_center ) . to receive ( :send_notifications ) . twice . with (
17431787 Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] , any_args
17441788 )
0 commit comments