@@ -361,6 +361,12 @@ class InvalidErrorHandler; end
361361 }
362362 end
363363
364+ it 'should return nil when user_id is empty or nil' do
365+ expect ( project_instance . track ( 'test_event' , '' , nil , 'revenue' => 42 ) ) . to eq ( nil )
366+ expect ( project_instance . track ( 'test_event' , nil , nil , 'revenue' => 42 ) ) . to eq ( nil )
367+ expect ( spy_logger ) . to have_received ( :log ) . twice . with ( Logger ::ERROR , 'User ID cannot be empty.' )
368+ end
369+
364370 it 'should properly track an event by calling dispatch_event with right params' do
365371 params = @expected_track_event_params
366372
@@ -529,6 +535,12 @@ class InvalidErrorHandler; end
529535 end
530536
531537 describe '#get_variation' do
538+ it 'should return nil when user_id is empty or nil' do
539+ expect ( project_instance . get_variation ( 'test_experiment_with_audience' , '' , nil ) ) . to eq ( nil )
540+ expect ( project_instance . get_variation ( 'test_experiment_with_audience' , nil , nil ) ) . to eq ( nil )
541+ expect ( spy_logger ) . to have_received ( :log ) . twice . with ( Logger ::ERROR , 'User ID cannot be empty.' )
542+ end
543+
532544 it 'should have get_variation return expected variation when there are no audiences' do
533545 expect ( project_instance . get_variation ( 'test_experiment' , 'test_user' ) )
534546 . to eq ( config_body [ 'experiments' ] [ 0 ] [ 'variations' ] [ 0 ] [ 'key' ] )
@@ -1012,10 +1024,12 @@ class InvalidErrorHandler; end
10121024 expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::ERROR , 'Variable key cannot be empty.' )
10131025 end
10141026
1015- it 'should return nil if user_id is nil' do
1027+ it 'should return nil if user_id is empty or nil' do
10161028 expect ( project_instance . get_feature_variable_integer ( 'integer_single_variable_feature' , 'integer_variable' , nil , user_attributes ) )
10171029 . to eq ( nil )
1018- expect ( spy_logger ) . to have_received ( :log ) . once . with ( Logger ::ERROR , 'User ID cannot be empty.' )
1030+ expect ( project_instance . get_feature_variable_integer ( 'integer_single_variable_feature' , 'integer_variable' , '' , user_attributes ) )
1031+ . to eq ( nil )
1032+ expect ( spy_logger ) . to have_received ( :log ) . twice . with ( Logger ::ERROR , 'User ID cannot be empty.' )
10191033 end
10201034 end
10211035
0 commit comments