@@ -112,73 +112,6 @@ describe('EppoPrecomputedClient E2E test', () => {
112112 } ) ;
113113 } ) ;
114114
115- describe ( 'store initialization logged errors' , ( ) => {
116- let mockError : jest . SpyInstance ;
117-
118- beforeEach ( ( ) => {
119- mockError = jest . spyOn ( applicationLogger , 'error' ) ;
120- } ) ;
121-
122- afterEach ( ( ) => {
123- mockError . mockRestore ( ) ;
124- } ) ;
125-
126- it ( 'logs error when initialized with store without salt' , ( ) => {
127- const emptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
128- new EppoPrecomputedClient ( {
129- precomputedFlagStore : emptyStore ,
130- subject : {
131- subjectKey : '' ,
132- subjectAttributes : { } ,
133- } ,
134- } ) ;
135- expect ( mockError ) . not . toHaveBeenCalledWith (
136- 'EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
137- ) ;
138- } ) ;
139-
140- it ( 'logs errors when constructor receives an uninitialized store without a salt' , ( ) => {
141- const nonemptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
142- // Incorrectly initialized: no salt, not set to initialized
143- jest . spyOn ( nonemptyStore , 'getKeys' ) . mockReturnValue ( [ 'some-key' ] ) ;
144-
145- new EppoPrecomputedClient ( {
146- precomputedFlagStore : nonemptyStore ,
147- subject : {
148- subjectKey : '' ,
149- subjectAttributes : { } ,
150- } ,
151- } ) ;
152- expect ( mockError ) . toHaveBeenCalledWith (
153- '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
154- ) ;
155- expect ( mockError ) . toHaveBeenCalledWith (
156- '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
157- ) ;
158- } ) ;
159-
160- it ( 'only logs initialization error when constructor receives an uninitialized store with salt' , ( ) => {
161- const nonemptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
162- nonemptyStore . salt = 'nacl' ;
163- // Incorrectly initialized: no salt, not set to initialized
164- jest . spyOn ( nonemptyStore , 'getKeys' ) . mockReturnValue ( [ 'some-key' ] ) ;
165-
166- new EppoPrecomputedClient ( {
167- precomputedFlagStore : nonemptyStore ,
168- subject : {
169- subjectKey : '' ,
170- subjectAttributes : { } ,
171- } ,
172- } ) ;
173- expect ( mockError ) . toHaveBeenCalledWith (
174- '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
175- ) ;
176- expect ( mockError ) . not . toHaveBeenCalledWith (
177- '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
178- ) ;
179- } ) ;
180- } ) ;
181-
182115 describe ( 'setLogger' , ( ) => {
183116 let flagStorage : IConfigurationStore < PrecomputedFlag > ;
184117 let subject : Subject ;
@@ -835,6 +768,77 @@ describe('EppoPrecomputedClient E2E test', () => {
835768 expect ( loggedEvent . format ) . toEqual ( FormatEnum . PRECOMPUTED ) ;
836769 } ) ;
837770
771+
772+ describe ( 'Constructor logs errors according to the store state' , ( ) => {
773+ let mockError : jest . SpyInstance ;
774+
775+ beforeEach ( ( ) => {
776+ mockError = jest . spyOn ( applicationLogger , 'error' ) ;
777+ } ) ;
778+
779+ afterEach ( ( ) => {
780+ mockError . mockRestore ( ) ;
781+ } ) ;
782+
783+ it ( 'does not log errors when constructor receives an empty, uninitialized store' , ( ) => {
784+ const emptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
785+ new EppoPrecomputedClient ( {
786+ precomputedFlagStore : emptyStore ,
787+ subject : {
788+ subjectKey : '' ,
789+ subjectAttributes : { } ,
790+ } ,
791+ } ) ;
792+ expect ( mockError ) . not . toHaveBeenCalledWith (
793+ '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
794+ ) ;
795+ expect ( mockError ) . not . toHaveBeenCalledWith (
796+ '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
797+ ) ;
798+ } ) ;
799+
800+ it ( 'logs errors when constructor receives an uninitialized store without a salt' , ( ) => {
801+ const nonemptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
802+ // Incorrectly initialized: no salt, not set to initialized
803+ jest . spyOn ( nonemptyStore , 'getKeys' ) . mockReturnValue ( [ 'some-key' ] ) ;
804+
805+ new EppoPrecomputedClient ( {
806+ precomputedFlagStore : nonemptyStore ,
807+ subject : {
808+ subjectKey : '' ,
809+ subjectAttributes : { } ,
810+ } ,
811+ } ) ;
812+ expect ( mockError ) . toHaveBeenCalledWith (
813+ '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
814+ ) ;
815+ expect ( mockError ) . toHaveBeenCalledWith (
816+ '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
817+ ) ;
818+ } ) ;
819+
820+ it ( 'only logs initialization error when constructor receives an uninitialized store with salt' , ( ) => {
821+ const nonemptyStore = new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ;
822+ nonemptyStore . salt = 'nacl' ;
823+ // Incorrectly initialized: no salt, not set to initialized
824+ jest . spyOn ( nonemptyStore , 'getKeys' ) . mockReturnValue ( [ 'some-key' ] ) ;
825+
826+ new EppoPrecomputedClient ( {
827+ precomputedFlagStore : nonemptyStore ,
828+ subject : {
829+ subjectKey : '' ,
830+ subjectAttributes : { } ,
831+ } ,
832+ } ) ;
833+ expect ( mockError ) . toHaveBeenCalledWith (
834+ '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
835+ ) ;
836+ expect ( mockError ) . not . toHaveBeenCalledWith (
837+ '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
838+ ) ;
839+ } ) ;
840+ } ) ;
841+
838842 describe ( 'EppoPrecomputedClient subject data and store initialization' , ( ) => {
839843 let client : EppoPrecomputedClient ;
840844 let store : IConfigurationStore < PrecomputedFlag > ;
@@ -853,13 +857,7 @@ describe('EppoPrecomputedClient E2E test', () => {
853857 subject,
854858 } ) ;
855859 } ) . not . toThrow ( ) ;
856- expect ( loggerErrorSpy ) . toHaveBeenCalledTimes ( 2 ) ;
857- expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
858- '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
859- ) ;
860- expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
861- '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
862- ) ;
860+ expect ( loggerErrorSpy ) . toHaveBeenCalledTimes ( 0 ) ;
863861 loggerErrorSpy . mockRestore ( ) ;
864862 expect ( client . getStringAssignment ( 'string-flag' , 'default' ) ) . toBe ( 'default' ) ;
865863 } ) ;
@@ -953,12 +951,6 @@ describe('Precomputed Bandit Store', () => {
953951 subject,
954952 } ) ;
955953
956- expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
957- '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided' ,
958- ) ;
959- expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
960- '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided' ,
961- ) ;
962954 expect ( loggerErrorSpy ) . toHaveBeenCalledWith (
963955 '[Eppo SDK] Passing banditOptions without requestParameters requires an initialized precomputedBanditStore' ,
964956 ) ;
0 commit comments