@@ -121,6 +121,7 @@ class InvalidErrorHandler; end
121
121
before ( :example ) do
122
122
allow ( Time ) . to receive ( :now ) . and_return ( time_now )
123
123
allow ( SecureRandom ) . to receive ( :uuid ) . and_return ( 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c' ) ;
124
+
124
125
@expected_activate_params = {
125
126
account_id : '12001' ,
126
127
project_id : '111001' ,
@@ -271,7 +272,7 @@ class InvalidErrorHandler; end
271
272
instance_of ( Optimizely ::Event )
272
273
)
273
274
project_instance . activate ( 'test_experiment' , 'test_user' )
274
-
275
+
275
276
expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::INFO , include ( "Dispatching impression event to" \
276
277
" URL #{ impression_log_url } with params #{ params } " ) )
277
278
end
@@ -288,7 +289,7 @@ class InvalidErrorHandler; end
288
289
expect { project_instance . activate ( 'test_experiment' , 'test_user' , 'invalid' ) }
289
290
. to raise_error ( Optimizely ::InvalidAttributeFormatError )
290
291
end
291
-
292
+
292
293
it 'should override the audience check if the user is whitelisted to a specific variation' do
293
294
params = @expected_activate_params
294
295
params [ :visitors ] [ 0 ] [ :visitor_id ] = 'forced_audience_user'
@@ -330,7 +331,7 @@ class InvalidErrorHandler; end
330
331
before ( :example ) do
331
332
allow ( Time ) . to receive ( :now ) . and_return ( time_now )
332
333
allow ( SecureRandom ) . to receive ( :uuid ) . and_return ( 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c' ) ;
333
-
334
+
334
335
@expected_track_event_params = {
335
336
account_id : '12001' ,
336
337
project_id : '111001' ,
@@ -365,7 +366,7 @@ class InvalidErrorHandler; end
365
366
project_instance . track ( 'test_event' , 'test_user' )
366
367
expect ( project_instance . event_dispatcher ) . to have_received ( :dispatch_event ) . with ( Optimizely ::Event . new ( :post , conversion_log_url , params , post_headers ) ) . once
367
368
end
368
-
369
+
369
370
it 'should properly track an event by calling dispatch_event with right params after forced variation' do
370
371
params = @expected_track_event_params
371
372
params [ :visitors ] [ 0 ] [ :snapshots ] [ 0 ] [ :decisions ] [ 0 ] [ :variation_id ] = '111129'
@@ -548,15 +549,15 @@ class InvalidErrorHandler; end
548
549
expect ( project_instance . get_variation ( 'test_experiment_with_audience' , 'test_user' , user_attributes ) )
549
550
. to eq ( 'control_with_audience' )
550
551
end
551
-
552
+
552
553
it 'should have get_variation return expected variation with bucketing id attribute when audience conditions match' do
553
554
user_attributes = {
554
555
'browser_type' => 'firefox' ,
555
556
OptimizelySpec ::RESERVED_ATTRIBUTE_KEY_BUCKETING_ID => 'pid'
556
- }
557
+ }
557
558
expect ( project_instance . get_variation ( 'test_experiment_with_audience' , 'test_user' , user_attributes ) )
558
559
. to eq ( 'control_with_audience' )
559
- end
560
+ end
560
561
561
562
it 'should have get_variation return nil when attributes are invalid' do
562
563
allow ( project_instance ) . to receive ( :attributes_valid? ) . and_return ( false )
@@ -586,7 +587,7 @@ class InvalidErrorHandler; end
586
587
user_attributes = {
587
588
'browser_type' => 'firefox' ,
588
589
OptimizelySpec ::RESERVED_ATTRIBUTE_KEY_BUCKETING_ID => 'pid'
589
- }
590
+ }
590
591
expect ( project_instance . get_variation ( 'test_experiment_not_started' , 'test_user' , user_attributes ) ) . to eq ( nil )
591
592
end
592
593
@@ -647,12 +648,12 @@ class InvalidErrorHandler; end
647
648
}
648
649
end
649
650
650
- it 'should return nil when called with invalid project config' do
651
+ it 'should return false when called with invalid project config' do
651
652
invalid_project = Optimizely ::Project . new ( 'invalid' , nil , spy_logger )
652
- expect ( invalid_project . is_feature_enabled ( 'totally_invalid_feature_key' , 'test_user' ) ) . to be nil
653
-
653
+ expect ( invalid_project . is_feature_enabled ( 'totally_invalid_feature_key' , 'test_user' ) ) . to be false
654
+
654
655
end
655
-
656
+
656
657
it 'should return false when the feature flag key is invalid' do
657
658
expect ( project_instance . is_feature_enabled ( 'totally_invalid_feature_key' , 'test_user' ) ) . to be false
658
659
expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::ERROR , "Feature flag key 'totally_invalid_feature_key' is not in datafile." )
@@ -691,14 +692,14 @@ class InvalidErrorHandler; end
691
692
variation_to_return ,
692
693
Optimizely ::DecisionService ::DECISION_SOURCE_EXPERIMENT
693
694
)
694
-
695
+
695
696
expect ( project_instance . notification_center ) . to receive ( :send_notifications )
696
697
. with (
697
698
Optimizely ::NotificationCenter ::NOTIFICATION_TYPES [ :ACTIVATE ] ,
698
699
experiment_to_return , 'test_user' , nil , variation_to_return ,
699
700
instance_of ( Optimizely ::Event )
700
701
)
701
-
702
+
702
703
allow ( project_instance . decision_service ) . to receive ( :get_variation_for_feature ) . and_return ( decision_to_return )
703
704
704
705
expected_params = @expected_bucketed_params
@@ -976,7 +977,7 @@ class InvalidErrorHandler; end
976
977
expect ( project_instance . get_variation ( 'test_experiment' , 'test_user' ) ) . to eq ( 'variation' )
977
978
end
978
979
979
- # setForcedVariation on a running experiment with audience enabled and then call getVariation on that same experiment with invalid attributes.
980
+ # setForcedVariation on a running experiment with audience enabled and then call getVariation on that same experiment with invalid attributes.
980
981
it 'should return nil when getVariation called on audience enabled running experiment with invalid attributes' do
981
982
project_instance . set_forced_variation ( 'test_experiment_with_audience' , 'test_user' , 'control_with_audience' )
982
983
expect { project_instance . get_variation ( 'test_experiment_with_audience' , 'test_user' , 'invalid' ) }
@@ -986,7 +987,7 @@ class InvalidErrorHandler; end
986
987
# Adding this test case to cover this in code coverage. All test cases for getForceVariation are present in
987
988
# project_config_spec.rb which test the get_force_variation method in project_config. The one in optimizely.rb
988
989
# only calls the other one
989
-
990
+
990
991
# getForceVariation on a running experiment after setforcevariation
991
992
it 'should return expected variation id when get_forced_variation is called on a running experiment after setForcedVariation' do
992
993
project_instance . set_forced_variation ( 'test_experiment' , 'test_user' , 'variation' )
0 commit comments