@@ -17,6 +17,7 @@ import {UnknownError} from './errors/unknownError';
17
17
import { Unauthorized } from './errors/unauthorized' ;
18
18
import { GoFeatureFlagProvider } from './go-feature-flag-provider' ;
19
19
import { GoFeatureFlagProxyResponse } from './model' ;
20
+ import TestLogger from './test-logger' ;
20
21
21
22
describe ( 'GoFeatureFlagProvider' , ( ) => {
22
23
const endpoint = 'http://go-feature-flag-relay-proxy.local:1031/' ;
@@ -35,12 +36,15 @@ describe('GoFeatureFlagProvider', () => {
35
36
} ,
36
37
cacheable : true ,
37
38
} ;
39
+
38
40
let goff : GoFeatureFlagProvider ;
41
+ const testLogger = new TestLogger ( ) ;
39
42
40
43
afterEach ( async ( ) => {
41
44
await OpenFeature . close ( ) ;
42
45
await axiosMock . reset ( ) ;
43
46
await axiosMock . resetHistory ( ) ;
47
+ testLogger . reset ( ) ;
44
48
} ) ;
45
49
46
50
beforeEach ( async ( ) => {
@@ -907,5 +911,31 @@ describe('GoFeatureFlagProvider', () => {
907
911
908
912
expect ( collectorCalls . length ) . toBe ( 0 ) ;
909
913
} ) ;
914
+
915
+ it ( 'should have a log when data collector is not available' , async ( ) => {
916
+ const flagName = 'random-flag' ;
917
+ const targetingKey = 'user-key' ;
918
+ const dns = `${ endpoint } v1/feature/${ flagName } /eval` ;
919
+
920
+ axiosMock . onPost ( dns ) . reply ( 200 , validBoolResponse ) ;
921
+ axiosMock . onPost ( dataCollectorEndpoint ) . reply ( 500 , { } ) ;
922
+
923
+ const goff = new GoFeatureFlagProvider ( {
924
+ endpoint,
925
+ flagCacheTTL : 3000 ,
926
+ flagCacheSize : 100 ,
927
+ dataFlushInterval : 2000 , // in milliseconds
928
+ } , testLogger )
929
+ const providerName = expect . getState ( ) . currentTestName || 'test' ;
930
+ OpenFeature . setProvider ( providerName , goff ) ;
931
+ const cli = OpenFeature . getClient ( providerName ) ;
932
+ await cli . getBooleanDetails ( flagName , false , { targetingKey} ) ;
933
+ await cli . getBooleanDetails ( flagName , false , { targetingKey} ) ;
934
+ await OpenFeature . close ( ) ;
935
+
936
+ console . log ( testLogger )
937
+ expect ( testLogger . inMemoryLogger [ 'error' ] . length ) . toBe ( 1 ) ;
938
+ expect ( testLogger . inMemoryLogger [ 'error' ] ) . toContain ( 'impossible to send the data to the collector: Error: Request failed with status code 500' )
939
+ } ) ;
910
940
} ) ;
911
941
} ) ;
0 commit comments