@@ -430,7 +430,8 @@ describe('EppoPrecomputedClient E2E test', () => {
430
430
} ) ;
431
431
432
432
it ( 'Fetches initial configuration with parameters in constructor' , async ( ) => {
433
- client = new EppoPrecomputedClient ( precomputedFlagStore , requestParameters ) ;
433
+ client = new EppoPrecomputedClient ( precomputedFlagStore ) ;
434
+ client . setSubjectAndPrecomputedFlagsRequestParameters ( requestParameters ) ;
434
435
// no configuration loaded
435
436
let variation = client . getStringAssignment ( precomputedFlagKey , 'default' ) ;
436
437
expect ( variation ) . toBe ( 'default' ) ;
@@ -442,7 +443,7 @@ describe('EppoPrecomputedClient E2E test', () => {
442
443
443
444
it ( 'Fetches initial configuration with parameters provided later' , async ( ) => {
444
445
client = new EppoPrecomputedClient ( precomputedFlagStore ) ;
445
- client . setPrecomputedFlagsRequestParameters ( requestParameters ) ;
446
+ client . setSubjectAndPrecomputedFlagsRequestParameters ( requestParameters ) ;
446
447
// no configuration loaded
447
448
let variation = client . getStringAssignment ( precomputedFlagKey , 'default' ) ;
448
449
expect ( variation ) . toBe ( 'default' ) ;
@@ -462,7 +463,8 @@ describe('EppoPrecomputedClient E2E test', () => {
462
463
}
463
464
}
464
465
465
- client = new EppoPrecomputedClient ( new MockStore ( ) , {
466
+ client = new EppoPrecomputedClient ( new MockStore ( ) ) ;
467
+ client . setSubjectAndPrecomputedFlagsRequestParameters ( {
466
468
...requestParameters ,
467
469
pollAfterSuccessfulInitialization : true ,
468
470
} ) ;
@@ -491,7 +493,8 @@ describe('EppoPrecomputedClient E2E test', () => {
491
493
}
492
494
}
493
495
494
- client = new EppoPrecomputedClient ( new MockStore ( ) , requestParameters ) ;
496
+ client = new EppoPrecomputedClient ( new MockStore ( ) ) ;
497
+ client . setSubjectAndPrecomputedFlagsRequestParameters ( requestParameters ) ;
495
498
// no configuration loaded
496
499
let variation = client . getStringAssignment ( precomputedFlagKey , 'default' ) ;
497
500
expect ( variation ) . toBe ( 'default' ) ;
@@ -505,7 +508,8 @@ describe('EppoPrecomputedClient E2E test', () => {
505
508
let client : EppoPrecomputedClient ;
506
509
507
510
beforeEach ( async ( ) => {
508
- client = new EppoPrecomputedClient ( storage , requestParameters ) ;
511
+ client = new EppoPrecomputedClient ( storage ) ;
512
+ client . setSubjectAndPrecomputedFlagsRequestParameters ( requestParameters ) ;
509
513
await client . fetchPrecomputedFlags ( ) ;
510
514
} ) ;
511
515
@@ -576,7 +580,8 @@ describe('EppoPrecomputedClient E2E test', () => {
576
580
...requestParameters ,
577
581
pollAfterSuccessfulInitialization,
578
582
} ;
579
- client = new EppoPrecomputedClient ( precomputedFlagStore , requestParameters ) ;
583
+ client = new EppoPrecomputedClient ( precomputedFlagStore ) ;
584
+ client . setSubjectAndPrecomputedFlagsRequestParameters ( requestParameters ) ;
580
585
// no configuration loaded
581
586
let variation = client . getStringAssignment ( precomputedFlagKey , 'default' ) ;
582
587
expect ( variation ) . toBe ( 'default' ) ;
@@ -640,7 +645,8 @@ describe('EppoPrecomputedClient E2E test', () => {
640
645
throwOnFailedInitialization,
641
646
pollAfterFailedInitialization,
642
647
} ;
643
- client = new EppoPrecomputedClient ( precomputedFlagStore , requestParameters ) ;
648
+ client = new EppoPrecomputedClient ( precomputedFlagStore ) ;
649
+ client . setSubjectAndPrecomputedFlagsRequestParameters ( requestParameters ) ;
644
650
// no configuration loaded
645
651
expect ( client . getStringAssignment ( precomputedFlagKey , 'default' ) ) . toBe ( 'default' ) ;
646
652
@@ -678,7 +684,7 @@ describe('EppoPrecomputedClient E2E test', () => {
678
684
extraLogging : { } ,
679
685
} ,
680
686
} ) ;
681
- client = new EppoPrecomputedClient ( storage , undefined , true ) ;
687
+ client = new EppoPrecomputedClient ( storage , true ) ;
682
688
} ) ;
683
689
684
690
afterAll ( ( ) => {
@@ -705,4 +711,51 @@ describe('EppoPrecomputedClient E2E test', () => {
705
711
706
712
expect ( loggedEvent . format ) . toEqual ( FormatEnum . PRECOMPUTED ) ;
707
713
} ) ;
714
+
715
+ describe ( 'EppoPrecomputedClient subject data and store initialization' , ( ) => {
716
+ let client : EppoPrecomputedClient ;
717
+ let store : IConfigurationStore < PrecomputedFlag > ;
718
+ let mockLogger : IAssignmentLogger ;
719
+
720
+ beforeEach ( ( ) => {
721
+ store = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
722
+ mockLogger = td . object < IAssignmentLogger > ( ) ;
723
+ client = new EppoPrecomputedClient ( store ) ;
724
+ client . setAssignmentLogger ( mockLogger ) ;
725
+ } ) ;
726
+
727
+ it ( 'returns default value and does not log when store is not initialized' , ( ) => {
728
+ client . setSubjectAndPrecomputedFlagStore ( 'test-subject' , { } , store ) ;
729
+ expect ( client . getStringAssignment ( 'test-flag' , 'default' ) ) . toBe ( 'default' ) ;
730
+ expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toEqual ( 0 ) ;
731
+ } ) ;
732
+
733
+ it ( 'returns assignment and logs subject data after store is initialized with flags' , async ( ) => {
734
+ const subjectKey = 'test-subject' ;
735
+ const subjectAttributes = { attr1 : 'value1' } ;
736
+
737
+ await store . setEntries ( {
738
+ 'test-flag' : {
739
+ variationType : VariationType . STRING ,
740
+ variationKey : 'control' ,
741
+ variationValue : 'test-value' ,
742
+ allocationKey : 'allocation-1' ,
743
+ doLog : true ,
744
+ extraLogging : { } ,
745
+ } ,
746
+ } ) ;
747
+ client . setSubjectAndPrecomputedFlagStore ( subjectKey , subjectAttributes , store ) ;
748
+ expect ( client . getStringAssignment ( 'test-flag' , 'default' ) ) . toBe ( 'test-value' ) ;
749
+
750
+ expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toEqual ( 1 ) ;
751
+ const loggedEvent = td . explain ( mockLogger . logAssignment ) . calls [ 0 ] . args [ 0 ] ;
752
+ expect ( loggedEvent . subject ) . toEqual ( subjectKey ) ;
753
+ expect ( loggedEvent . subjectAttributes ) . toEqual ( subjectAttributes ) ;
754
+ } ) ;
755
+
756
+ it ( 'returns default value and does not log when subject data is not set' , ( ) => {
757
+ expect ( client . getStringAssignment ( 'test-flag' , 'default' ) ) . toBe ( 'default' ) ;
758
+ expect ( td . explain ( mockLogger . logAssignment ) . callCount ) . toEqual ( 0 ) ;
759
+ } ) ;
760
+ } ) ;
708
761
} ) ;
0 commit comments