@@ -55,10 +55,12 @@ import {
55
55
USER_MEETS_CONDITIONS_FOR_TARGETING_RULE ,
56
56
USER_NOT_BUCKETED_INTO_TARGETING_RULE ,
57
57
USER_NOT_IN_ROLLOUT ,
58
- VALID_BUCKETING_ID
58
+ VALID_BUCKETING_ID ,
59
+ SAVED_USER_VARIATION ,
60
+ SAVED_VARIATION_NOT_FOUND
59
61
} from '../../log_messages' ;
60
62
import { mock } from 'node:test' ;
61
- import { BUCKETING_ID_NOT_STRING } from '../../error_messages' ;
63
+ import { BUCKETING_ID_NOT_STRING , USER_PROFILE_LOOKUP_ERROR , USER_PROFILE_SAVE_ERROR } from '../../error_messages' ;
62
64
63
65
var testData = getTestProjectConfig ( ) ;
64
66
var testDataWithFeatures = getTestProjectConfigWithFeatures ( ) ;
@@ -344,14 +346,20 @@ describe('lib/core/decision_service', function() {
344
346
) ;
345
347
sinon . assert . calledWith ( userProfileLookupStub , 'decision_service_user' ) ;
346
348
sinon . assert . calledOnce ( bucketerStub ) ;
347
- assert . strictEqual (
348
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
349
- 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
350
- ) ;
351
- assert . strictEqual (
352
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
353
- 'DECISION_SERVICE: User decision_service_user was previously bucketed into variation with ID not valid variation for experiment testExperiment, but no matching variation was found.'
349
+ // assert.strictEqual(
350
+ // buildLogMessageFromArgs(mockLogger.log.args[0]),
351
+ // 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
352
+ // );
353
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ USER_HAS_NO_FORCED_VARIATION , 'decision_service_user' ] ) ;
354
+
355
+ sinon . assert . calledWith (
356
+ mockLogger . info ,
357
+ SAVED_VARIATION_NOT_FOUND ,
358
+ 'decision_service_user' ,
359
+ 'not valid variation' ,
360
+ 'testExperiment'
354
361
) ;
362
+
355
363
// make sure we save the decision
356
364
sinon . assert . calledWith ( userProfileSaveStub , {
357
365
user_id : 'decision_service_user' ,
@@ -382,7 +390,7 @@ describe('lib/core/decision_service', function() {
382
390
) ;
383
391
sinon . assert . calledWith ( userProfileLookupStub , 'decision_service_user' ) ;
384
392
sinon . assert . calledOnce ( bucketerStub ) ;
385
- assert . strictEqual ( 5 , mockLogger . log . callCount ) ;
393
+
386
394
sinon . assert . calledWith ( userProfileServiceInstance . save , {
387
395
user_id : 'decision_service_user' ,
388
396
experiment_bucket_map : {
@@ -391,14 +399,11 @@ describe('lib/core/decision_service', function() {
391
399
} ,
392
400
} ,
393
401
} ) ;
394
- assert . strictEqual (
395
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
396
- 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
397
- ) ;
398
- assert . strictEqual (
399
- buildLogMessageFromArgs ( mockLogger . log . args [ 4 ] ) ,
400
- 'DECISION_SERVICE: Saved user profile for user "decision_service_user".'
401
- ) ;
402
+
403
+
404
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ USER_HAS_NO_FORCED_VARIATION , 'decision_service_user' ] ) ;
405
+
406
+ assert . deepEqual ( mockLogger . info . lastCall . args , [ SAVED_USER_VARIATION , 'decision_service_user' ] ) ;
402
407
} ) ;
403
408
404
409
it ( 'should log an error message if "lookup" throws an error' , function ( ) {
@@ -417,14 +422,10 @@ describe('lib/core/decision_service', function() {
417
422
) ;
418
423
sinon . assert . calledWith ( userProfileLookupStub , 'decision_service_user' ) ;
419
424
sinon . assert . calledOnce ( bucketerStub ) ; // should still go through with bucketing
420
- assert . strictEqual (
421
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
422
- 'DECISION_SERVICE: Error while looking up user profile for user ID "decision_service_user": I am an error.'
423
- ) ;
424
- assert . strictEqual (
425
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
426
- 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
427
- ) ;
425
+
426
+ assert . deepEqual ( mockLogger . error . args [ 0 ] , [ USER_PROFILE_LOOKUP_ERROR , 'decision_service_user' , 'I am an error' ] ) ;
427
+
428
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ USER_HAS_NO_FORCED_VARIATION , 'decision_service_user' ] ) ;
428
429
} ) ;
429
430
430
431
it ( 'should log an error message if "save" throws an error' , function ( ) {
@@ -444,15 +445,10 @@ describe('lib/core/decision_service', function() {
444
445
sinon . assert . calledWith ( userProfileLookupStub , 'decision_service_user' ) ;
445
446
sinon . assert . calledOnce ( bucketerStub ) ; // should still go through with bucketing
446
447
447
- assert . strictEqual ( 5 , mockLogger . log . callCount ) ;
448
- assert . strictEqual (
449
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
450
- 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
451
- ) ;
452
- assert . strictEqual (
453
- buildLogMessageFromArgs ( mockLogger . log . args [ 4 ] ) ,
454
- 'DECISION_SERVICE: Error while saving user profile for user ID "decision_service_user": I am an error.'
455
- ) ;
448
+
449
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ USER_HAS_NO_FORCED_VARIATION , 'decision_service_user' ] ) ;
450
+
451
+ assert . deepEqual ( mockLogger . error . args [ 0 ] , [ USER_PROFILE_SAVE_ERROR , 'decision_service_user' , 'I am an error' ] ) ;
456
452
457
453
// make sure that we save the decision
458
454
sinon . assert . calledWith ( userProfileSaveStub , {
@@ -499,14 +495,10 @@ describe('lib/core/decision_service', function() {
499
495
) ;
500
496
sinon . assert . calledWith ( userProfileLookupStub , 'decision_service_user' ) ;
501
497
sinon . assert . notCalled ( bucketerStub ) ;
502
- assert . strictEqual (
503
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
504
- 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
505
- ) ;
506
- assert . strictEqual (
507
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
508
- 'DECISION_SERVICE: Returning previously activated variation "variation" of experiment "testExperiment" for user "decision_service_user" from user profile.'
509
- ) ;
498
+
499
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ USER_HAS_NO_FORCED_VARIATION , 'decision_service_user' ] ) ;
500
+
501
+ assert . deepEqual ( mockLogger . info . args [ 0 ] , [ RETURNING_STORED_VARIATION , 'variation' , 'testExperiment' , 'decision_service_user' ] ) ;
510
502
} ) ;
511
503
512
504
it ( 'should ignore attributes for a different experiment id' , function ( ) {
@@ -544,14 +536,10 @@ describe('lib/core/decision_service', function() {
544
536
) ;
545
537
sinon . assert . calledWith ( userProfileLookupStub , 'decision_service_user' ) ;
546
538
sinon . assert . notCalled ( bucketerStub ) ;
547
- assert . strictEqual (
548
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
549
- 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
550
- ) ;
551
- assert . strictEqual (
552
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
553
- 'DECISION_SERVICE: Returning previously activated variation "control" of experiment "testExperiment" for user "decision_service_user" from user profile.'
554
- ) ;
539
+
540
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ USER_HAS_NO_FORCED_VARIATION , 'decision_service_user' ] ) ;
541
+
542
+ assert . deepEqual ( mockLogger . info . args [ 0 ] , [ RETURNING_STORED_VARIATION , 'control' , 'testExperiment' , 'decision_service_user' ] ) ;
555
543
} ) ;
556
544
557
545
it ( 'should use attributes when the userProfileLookup variations for other experiments' , function ( ) {
@@ -589,14 +577,10 @@ describe('lib/core/decision_service', function() {
589
577
) ;
590
578
sinon . assert . calledWith ( userProfileLookupStub , 'decision_service_user' ) ;
591
579
sinon . assert . notCalled ( bucketerStub ) ;
592
- assert . strictEqual (
593
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
594
- 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
595
- ) ;
596
- assert . strictEqual (
597
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
598
- 'DECISION_SERVICE: Returning previously activated variation "variation" of experiment "testExperiment" for user "decision_service_user" from user profile.'
599
- ) ;
580
+
581
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ USER_HAS_NO_FORCED_VARIATION , 'decision_service_user' ] ) ;
582
+
583
+ assert . deepEqual ( mockLogger . info . args [ 0 ] , [ RETURNING_STORED_VARIATION , 'variation' , 'testExperiment' , 'decision_service_user' ] ) ;
600
584
} ) ;
601
585
602
586
it ( 'should use attributes when the userProfileLookup returns null' , function ( ) {
@@ -625,14 +609,10 @@ describe('lib/core/decision_service', function() {
625
609
) ;
626
610
sinon . assert . calledWith ( userProfileLookupStub , 'decision_service_user' ) ;
627
611
sinon . assert . notCalled ( bucketerStub ) ;
628
- assert . strictEqual (
629
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
630
- 'DECISION_SERVICE: User decision_service_user is not in the forced variation map.'
631
- ) ;
632
- assert . strictEqual (
633
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
634
- 'DECISION_SERVICE: Returning previously activated variation "variation" of experiment "testExperiment" for user "decision_service_user" from user profile.'
635
- ) ;
612
+
613
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ USER_HAS_NO_FORCED_VARIATION , 'decision_service_user' ] ) ;
614
+
615
+ assert . deepEqual ( mockLogger . info . args [ 0 ] , [ RETURNING_STORED_VARIATION , 'variation' , 'testExperiment' , 'decision_service_user' ] ) ;
636
616
} ) ;
637
617
} ) ;
638
618
} ) ;
@@ -671,8 +651,6 @@ describe('lib/core/decision_service', function() {
671
651
} ;
672
652
673
653
assert . deepEqual ( bucketerParams , expectedParams ) ;
674
-
675
- sinon . assert . notCalled ( mockLogger . log ) ;
676
654
} ) ;
677
655
} ) ;
678
656
@@ -708,15 +686,10 @@ describe('lib/core/decision_service', function() {
708
686
''
709
687
) . result
710
688
) ;
711
- assert . strictEqual ( 2 , mockLogger . log . callCount ) ;
712
- assert . strictEqual (
713
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
714
- 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].'
715
- ) ;
716
- assert . strictEqual (
717
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
718
- 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to TRUE.'
719
- ) ;
689
+
690
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ EVALUATING_AUDIENCES_COMBINED , 'experiment' , 'testExperimentWithAudiences' , JSON . stringify ( [ "11154" ] ) ] ) ;
691
+
692
+ assert . deepEqual ( mockLogger . info . args [ 0 ] , [ AUDIENCE_EVALUATION_RESULT_COMBINED , 'experiment' , 'testExperimentWithAudiences' , 'TRUE' ] ) ;
720
693
} ) ;
721
694
722
695
it ( 'should return decision response with result true when experiment has no audience' , function ( ) {
@@ -732,15 +705,9 @@ describe('lib/core/decision_service', function() {
732
705
) ;
733
706
assert . isTrue ( __audienceEvaluateSpy . alwaysReturned ( true ) ) ;
734
707
735
- assert . strictEqual ( 2 , mockLogger . log . callCount ) ;
736
- assert . strictEqual (
737
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
738
- 'DECISION_SERVICE: Evaluating audiences for experiment "testExperiment": [].'
739
- ) ;
740
- assert . strictEqual (
741
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
742
- 'DECISION_SERVICE: Audiences for experiment testExperiment collectively evaluated to TRUE.'
743
- ) ;
708
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ EVALUATING_AUDIENCES_COMBINED , 'experiment' , 'testExperiment' , JSON . stringify ( [ ] ) ] ) ;
709
+
710
+ assert . deepEqual ( mockLogger . info . args [ 0 ] , [ AUDIENCE_EVALUATION_RESULT_COMBINED , 'experiment' , 'testExperiment' , 'TRUE' ] ) ;
744
711
} ) ;
745
712
746
713
it ( 'should return decision response with result false when audience conditions can not be evaluated' , function ( ) {
@@ -756,15 +723,9 @@ describe('lib/core/decision_service', function() {
756
723
) ;
757
724
assert . isTrue ( __audienceEvaluateSpy . alwaysReturned ( false ) ) ;
758
725
759
- assert . strictEqual ( 2 , mockLogger . log . callCount ) ;
760
- assert . strictEqual (
761
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
762
- 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].'
763
- ) ;
764
- assert . strictEqual (
765
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
766
- 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to FALSE.'
767
- ) ;
726
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ EVALUATING_AUDIENCES_COMBINED , 'experiment' , 'testExperimentWithAudiences' , JSON . stringify ( [ "11154" ] ) ] ) ;
727
+
728
+ assert . deepEqual ( mockLogger . info . args [ 0 ] , [ AUDIENCE_EVALUATION_RESULT_COMBINED , 'experiment' , 'testExperimentWithAudiences' , 'FALSE' ] ) ;
768
729
} ) ;
769
730
770
731
it ( 'should return decision response with result false when audience conditions are not met' , function ( ) {
@@ -780,15 +741,10 @@ describe('lib/core/decision_service', function() {
780
741
) ;
781
742
assert . isTrue ( __audienceEvaluateSpy . alwaysReturned ( false ) ) ;
782
743
783
- assert . strictEqual ( 2 , mockLogger . log . callCount ) ;
784
- assert . strictEqual (
785
- buildLogMessageFromArgs ( mockLogger . log . args [ 0 ] ) ,
786
- 'DECISION_SERVICE: Evaluating audiences for experiment "testExperimentWithAudiences": ["11154"].'
787
- ) ;
788
- assert . strictEqual (
789
- buildLogMessageFromArgs ( mockLogger . log . args [ 1 ] ) ,
790
- 'DECISION_SERVICE: Audiences for experiment testExperimentWithAudiences collectively evaluated to FALSE.'
791
- ) ;
744
+
745
+ assert . deepEqual ( mockLogger . debug . args [ 0 ] , [ EVALUATING_AUDIENCES_COMBINED , 'experiment' , 'testExperimentWithAudiences' , JSON . stringify ( [ "11154" ] ) ] ) ;
746
+
747
+ assert . deepEqual ( mockLogger . info . args [ 0 ] , [ AUDIENCE_EVALUATION_RESULT_COMBINED , 'experiment' , 'testExperimentWithAudiences' , 'FALSE' ] ) ;
792
748
} ) ;
793
749
} ) ;
794
750
0 commit comments