@@ -52,6 +52,7 @@ describe('EppoPrecomputedClient E2E test', () => {
52
52
subjectKey : 'test-subject' ,
53
53
subjectAttributes : { attr1 : 'value1' } ,
54
54
} ;
55
+
55
56
beforeEach ( async ( ) => {
56
57
storage = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
57
58
storage . setFormat ( FormatEnum . PRECOMPUTED ) ;
@@ -766,6 +767,76 @@ describe('EppoPrecomputedClient E2E test', () => {
766
767
expect ( loggedEvent . format ) . toEqual ( FormatEnum . PRECOMPUTED ) ;
767
768
} ) ;
768
769
770
+ describe ( 'Constructor logs errors according to the store state' , ( ) => {
771
+ let mockError : jest . SpyInstance ;
772
+
773
+ beforeEach ( ( ) => {
774
+ mockError = jest . spyOn ( logger , 'error' ) ;
775
+ } ) ;
776
+
777
+ afterEach ( ( ) => {
778
+ mockError . mockRestore ( ) ;
779
+ } ) ;
780
+
781
+ it ( 'does not log errors when constructor receives an empty, uninitialized store' , ( ) => {
782
+ const emptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
783
+ new EppoPrecomputedClient ( {
784
+ precomputedFlagStore : emptyStore ,
785
+ subject : {
786
+ subjectKey : '' ,
787
+ subjectAttributes : { } ,
788
+ } ,
789
+ } ) ;
790
+ expect ( mockError ) . not . toHaveBeenCalledWith (
791
+ '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
792
+ ) ;
793
+ expect ( mockError ) . not . toHaveBeenCalledWith (
794
+ '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
795
+ ) ;
796
+ } ) ;
797
+
798
+ it ( 'logs errors when constructor receives an uninitialized store without a salt' , ( ) => {
799
+ const nonemptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
800
+ // Incorrectly initialized: no salt, not set to initialized
801
+ jest . spyOn ( nonemptyStore , 'getKeys' ) . mockReturnValue ( [ 'some-key' ] ) ;
802
+
803
+ new EppoPrecomputedClient ( {
804
+ precomputedFlagStore : nonemptyStore ,
805
+ subject : {
806
+ subjectKey : '' ,
807
+ subjectAttributes : { } ,
808
+ } ,
809
+ } ) ;
810
+ expect ( mockError ) . toHaveBeenCalledWith (
811
+ '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
812
+ ) ;
813
+ expect ( mockError ) . toHaveBeenCalledWith (
814
+ '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
815
+ ) ;
816
+ } ) ;
817
+
818
+ it ( 'only logs initialization error when constructor receives an uninitialized store with salt' , ( ) => {
819
+ const nonemptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
820
+ nonemptyStore . salt = 'nacl' ;
821
+ // Incorrectly initialized: no salt, not set to initialized
822
+ jest . spyOn ( nonemptyStore , 'getKeys' ) . mockReturnValue ( [ 'some-key' ] ) ;
823
+
824
+ new EppoPrecomputedClient ( {
825
+ precomputedFlagStore : nonemptyStore ,
826
+ subject : {
827
+ subjectKey : '' ,
828
+ subjectAttributes : { } ,
829
+ } ,
830
+ } ) ;
831
+ expect ( mockError ) . toHaveBeenCalledWith (
832
+ '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
833
+ ) ;
834
+ expect ( mockError ) . not . toHaveBeenCalledWith (
835
+ '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
836
+ ) ;
837
+ } ) ;
838
+ } ) ;
839
+
769
840
describe ( 'EppoPrecomputedClient subject data and store initialization' , ( ) => {
770
841
let client : EppoPrecomputedClient ;
771
842
let store : IConfigurationStore < PrecomputedFlag > ;
@@ -784,13 +855,7 @@ describe('EppoPrecomputedClient E2E test', () => {
784
855
subject,
785
856
} ) ;
786
857
} ) . not . toThrow ( ) ;
787
- expect ( loggerErrorSpy ) . toHaveBeenCalledTimes ( 2 ) ;
788
- expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
789
- '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
790
- ) ;
791
- expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
792
- '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
793
- ) ;
858
+ expect ( loggerErrorSpy ) . toHaveBeenCalledTimes ( 0 ) ;
794
859
loggerErrorSpy . mockRestore ( ) ;
795
860
expect ( client . getStringAssignment ( 'string-flag' , 'default' ) ) . toBe ( 'default' ) ;
796
861
} ) ;
@@ -884,12 +949,6 @@ describe('Precomputed Bandit Store', () => {
884
949
subject,
885
950
} ) ;
886
951
887
- expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
888
- '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
889
- ) ;
890
- expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
891
- '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
892
- ) ;
893
952
expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
894
953
'[Eppo SDK] Passing banditOptions without requestParameters requires an initialized precomputedBanditStore' ,
895
954
) ;
0 commit comments