@@ -52,6 +52,7 @@ describe('EppoPrecomputedClient E2E test', () => {
5252 subjectKey : 'test-subject' ,
5353 subjectAttributes : { attr1 : 'value1' } ,
5454 } ;
55+
5556 beforeEach ( async ( ) => {
5657 storage = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
5758 storage . setFormat ( FormatEnum . PRECOMPUTED ) ;
@@ -766,6 +767,76 @@ describe('EppoPrecomputedClient E2E test', () => {
766767 expect ( loggedEvent . format ) . toEqual ( FormatEnum . PRECOMPUTED ) ;
767768 } ) ;
768769
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+
769840 describe ( 'EppoPrecomputedClient subject data and store initialization' , ( ) => {
770841 let client : EppoPrecomputedClient ;
771842 let store : IConfigurationStore < PrecomputedFlag > ;
@@ -784,13 +855,7 @@ describe('EppoPrecomputedClient E2E test', () => {
784855 subject,
785856 } ) ;
786857 } ) . 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 ) ;
794859 loggerErrorSpy . mockRestore ( ) ;
795860 expect ( client . getStringAssignment ( 'string-flag' , 'default' ) ) . toBe ( 'default' ) ;
796861 } ) ;
@@ -884,12 +949,6 @@ describe('Precomputed Bandit Store', () => {
884949 subject,
885950 } ) ;
886951
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- ) ;
893952 expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
894953 '[Eppo SDK] Passing banditOptions without requestParameters requires an initialized precomputedBanditStore' ,
895954 ) ;
0 commit comments