8
8
subject . new ( "secret" , offline_config )
9
9
end
10
10
let ( :null_data ) { LaunchDarkly ::NullUpdateProcessor . new }
11
- let ( :config ) { LaunchDarkly ::Config . new ( { send_events : false , data_source : null_data } ) }
11
+ let ( :logger ) { double ( ) . as_null_object }
12
+ let ( :config ) { LaunchDarkly ::Config . new ( { send_events : false , data_source : null_data , logger : logger } ) }
12
13
let ( :client ) do
13
14
subject . new ( "secret" , config )
14
15
end
17
18
JSON . parse ( data , symbolize_names : true )
18
19
end
19
20
let ( :user ) do
20
- data = File . read ( File . join ( "spec" , "fixtures" , "user.json" ) )
21
- JSON . parse ( data , symbolize_names : true )
21
+ {
22
+ key : "user@test.com" ,
23
+ custom : {
24
+ groups : [ "microsoft" , "google" ]
25
+ }
26
+ }
22
27
end
23
28
let ( :numeric_key_user ) do
24
- data = File . read ( File . join ( "spec" , "fixtures" , "numeric_key_user.json" ) )
25
- JSON . parse ( data , symbolize_names : true )
29
+ {
30
+ key : 33 ,
31
+ custom : {
32
+ groups : [ "microsoft" , "google" ]
33
+ }
34
+ }
26
35
end
27
36
let ( :sanitized_numeric_key_user ) do
28
- data = File . read ( File . join ( "spec" , "fixtures" , "sanitized_numeric_key_user.json" ) )
29
- JSON . parse ( data , symbolize_names : true )
37
+ {
38
+ key : "33" ,
39
+ custom : {
40
+ groups : [ "microsoft" , "google" ]
41
+ }
42
+ }
43
+ end
44
+ let ( :user_without_key ) do
45
+ { name : "Keyless Joe" }
30
46
end
31
47
32
48
def event_processor
@@ -342,6 +358,18 @@ def event_processor
342
358
expect ( event_processor ) . to receive ( :add_event ) . with ( hash_including ( user : sanitized_numeric_key_user ) )
343
359
client . track ( "custom_event_name" , numeric_key_user , nil )
344
360
end
361
+
362
+ it "does not send an event, and logs a warning, if user is nil" do
363
+ expect ( event_processor ) . not_to receive ( :add_event )
364
+ expect ( logger ) . to receive ( :warn )
365
+ client . track ( "custom_event_name" , nil , nil )
366
+ end
367
+
368
+ it "does not send an event, and logs a warning, if user key is nil" do
369
+ expect ( event_processor ) . not_to receive ( :add_event )
370
+ expect ( logger ) . to receive ( :warn )
371
+ client . track ( "custom_event_name" , user_without_key , nil )
372
+ end
345
373
end
346
374
347
375
describe '#identify' do
@@ -354,6 +382,18 @@ def event_processor
354
382
expect ( event_processor ) . to receive ( :add_event ) . with ( hash_including ( user : sanitized_numeric_key_user ) )
355
383
client . identify ( numeric_key_user )
356
384
end
385
+
386
+ it "does not send an event, and logs a warning, if user is nil" do
387
+ expect ( event_processor ) . not_to receive ( :add_event )
388
+ expect ( logger ) . to receive ( :warn )
389
+ client . identify ( nil )
390
+ end
391
+
392
+ it "does not send an event, and logs a warning, if user key is nil" do
393
+ expect ( event_processor ) . not_to receive ( :add_event )
394
+ expect ( logger ) . to receive ( :warn )
395
+ client . identify ( user_without_key )
396
+ end
357
397
end
358
398
359
399
describe 'with send_events: false' do
0 commit comments