diff --git a/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.spec.ts b/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.spec.ts index 4a51233d8..0f5859405 100644 --- a/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.spec.ts +++ b/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.spec.ts @@ -5,6 +5,7 @@ import { ErrorCode, FlagNotFoundError, OpenFeature, + ProviderStatus, ResolutionDetails, StandardResolutionReasons, TypeMismatchError @@ -59,7 +60,6 @@ describe('GoFeatureFlagProvider', () => { const goff = new GoFeatureFlagProvider({endpoint}); expect(goff).toBeInstanceOf(GoFeatureFlagProvider); }); - it('should throw an error if proxy not ready', async () => { const flagName = 'random-flag'; const targetingKey = 'user-key'; @@ -74,7 +74,6 @@ describe('GoFeatureFlagProvider', () => { ); }); }); - it('should throw an error if the call timeout', async () => { const flagName = 'random-flag'; const targetingKey = 'user-key'; @@ -89,7 +88,6 @@ describe('GoFeatureFlagProvider', () => { ); }); }); - describe('error codes in HTTP response', () => { it('SDK error codes should return correct code', async () => { const flagName = 'random-other-flag'; @@ -106,7 +104,6 @@ describe('GoFeatureFlagProvider', () => { expect(result.errorCode).toEqual(ErrorCode.PARSE_ERROR) }) }); - it('unknown error codes should return GENERAL code', async () => { const flagName = 'random-other-other-flag'; const targetingKey = 'user-key'; @@ -123,7 +120,6 @@ describe('GoFeatureFlagProvider', () => { }) }); }); - it('should throw an error if we fail in other network errors case', async () => { const flagName = 'random-flag'; const targetingKey = 'user-key'; @@ -176,7 +172,6 @@ describe('GoFeatureFlagProvider', () => { ); }); }); - it('should be valid with an API key provided', async () => { const flagName = 'random-flag'; const targetingKey = 'user-key'; @@ -203,6 +198,14 @@ describe('GoFeatureFlagProvider', () => { } as ResolutionDetails); }); }); + it('provider should start not ready', async () => { + const goff = new GoFeatureFlagProvider({endpoint}); + expect(goff.status).toEqual(ProviderStatus.NOT_READY); + }); + it('provider should be ready after after setting the provider to Open Feature', async () => { + OpenFeature.setProvider( 'goff', goff); + expect(goff.status).toEqual(ProviderStatus.READY); + }); }); describe('resolveBooleanEvaluation', () => { @@ -298,7 +301,6 @@ describe('GoFeatureFlagProvider', () => { }); }); }); - describe('resolveStringEvaluation', () => { it('should throw an error if we expect a string and got another type', async () => { const flagName = 'random-flag'; @@ -393,7 +395,6 @@ describe('GoFeatureFlagProvider', () => { }); }); }); - describe('resolveNumberEvaluation', () => { it('should throw an error if we expect a number and got another type', async () => { const flagName = 'random-flag'; @@ -486,7 +487,6 @@ describe('GoFeatureFlagProvider', () => { }); }); }); - describe('resolveObjectEvaluation', () => { it('should throw an error if we expect a json array and got another type', async () => { const flagName = 'random-flag'; diff --git a/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.ts b/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.ts index 8619c0c1f..83c07ca8a 100644 --- a/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.ts +++ b/libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.ts @@ -5,6 +5,7 @@ import { JsonValue, Logger, Provider, + ProviderStatus, ResolutionDetails, StandardResolutionReasons, TypeMismatchError, @@ -68,6 +69,8 @@ export class GoFeatureFlagProvider implements Provider { // logger is the Open Feature logger to use private logger?: Logger; + private _status: ProviderStatus = ProviderStatus.NOT_READY; + constructor(options: GoFeatureFlagProviderOptions, logger?: Logger) { this.timeout = options.timeout || 0; // default is 0 = no timeout this.endpoint = options.endpoint; @@ -96,6 +99,11 @@ export class GoFeatureFlagProvider implements Provider { this.bgScheduler = setInterval(async () => await this.callGoffDataCollection(), this.dataFlushInterval) this.dataCollectorBuffer = [] } + this._status = ProviderStatus.READY; + } + + get status(){ + return this._status; } /**