From f1edb296346e9feb2bd86fed71bbe24e725e0531 Mon Sep 17 00:00:00 2001 From: Michael Beemer Date: Fri, 26 Aug 2022 14:30:37 -0400 Subject: [PATCH] fix: update the client to conform to the provider interface (#187) The resolve argument in the evaluation method was still using evaluation options. Signed-off-by: Michael Beemer --- src/client.ts | 9 ++------- test/client.spec.ts | 28 ++++++++++++---------------- test/hooks.spec.ts | 14 ++++++-------- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/client.ts b/src/client.ts index 64af79238..3616b8363 100644 --- a/src/client.ts +++ b/src/client.ts @@ -145,12 +145,7 @@ export class OpenFeatureClient implements Client { private async evaluate( flagKey: string, - resolver: ( - flagKey: string, - defaultValue: T, - context: EvaluationContext, - options: FlagEvaluationOptions | undefined - ) => Promise>, + resolver: (flagKey: string, defaultValue: T, context: EvaluationContext) => Promise>, defaultValue: T, flagType: FlagValueType, invocationContext: EvaluationContext = {}, @@ -183,7 +178,7 @@ export class OpenFeatureClient implements Client { const frozenContext = await this.beforeHooks(allHooks, hookContext, options); // run the referenced resolver, binding the provider. - const resolution = await resolver.call(this.provider, flagKey, defaultValue, frozenContext, options); + const resolution = await resolver.call(this.provider, flagKey, defaultValue, frozenContext); const evaluationDetails = { ...resolution, diff --git a/test/client.spec.ts b/test/client.spec.ts index 992c2b9bf..3cb0b4fd4 100644 --- a/test/client.spec.ts +++ b/test/client.spec.ts @@ -91,7 +91,7 @@ describe(OpenFeatureClient.name, () => { const value = await client.getBooleanValue(booleanFlag, defaultBooleanValue); expect(value).toEqual(BOOLEAN_VALUE); - expect(MOCK_PROVIDER.resolveBooleanEvaluation).toHaveBeenCalledWith(booleanFlag, defaultBooleanValue, {}, {}); + expect(MOCK_PROVIDER.resolveBooleanEvaluation).toHaveBeenCalledWith(booleanFlag, defaultBooleanValue, {}); }); }); @@ -102,7 +102,7 @@ describe(OpenFeatureClient.name, () => { const value = await client.getStringValue(stringFlag, defaultStringValue); expect(value).toEqual(STRING_VALUE); - expect(MOCK_PROVIDER.resolveStringEvaluation).toHaveBeenCalledWith(stringFlag, defaultStringValue, {}, {}); + expect(MOCK_PROVIDER.resolveStringEvaluation).toHaveBeenCalledWith(stringFlag, defaultStringValue, {}); }); }); @@ -113,7 +113,7 @@ describe(OpenFeatureClient.name, () => { const value = await client.getNumberValue(numberFlag, defaultNumberValue); expect(value).toEqual(NUMBER_VALUE); - expect(MOCK_PROVIDER.resolveNumberEvaluation).toHaveBeenCalledWith(numberFlag, defaultNumberValue, {}, {}); + expect(MOCK_PROVIDER.resolveNumberEvaluation).toHaveBeenCalledWith(numberFlag, defaultNumberValue, {}); }); }); @@ -124,7 +124,7 @@ describe(OpenFeatureClient.name, () => { const value = await client.getObjectValue(objectFlag, {}); expect(value).toEqual(OBJECT_VALUE); - expect(MOCK_PROVIDER.resolveObjectEvaluation).toHaveBeenCalledWith(objectFlag, defaultObjectFlag, {}, {}); + expect(MOCK_PROVIDER.resolveObjectEvaluation).toHaveBeenCalledWith(objectFlag, defaultObjectFlag, {}); }); }); }); @@ -146,7 +146,7 @@ describe(OpenFeatureClient.name, () => { expect(booleanDetails.value).toEqual(BOOLEAN_VALUE); expect(booleanDetails.variant).toEqual(BOOLEAN_VARIANT); - expect(MOCK_PROVIDER.resolveBooleanEvaluation).toHaveBeenCalledWith(booleanFlag, defaultBooleanValue, {}, {}); + expect(MOCK_PROVIDER.resolveBooleanEvaluation).toHaveBeenCalledWith(booleanFlag, defaultBooleanValue, {}); }); }); @@ -158,7 +158,7 @@ describe(OpenFeatureClient.name, () => { expect(stringDetails.value).toEqual(STRING_VALUE); expect(stringDetails.variant).toEqual(STRING_VARIANT); - expect(MOCK_PROVIDER.resolveStringEvaluation).toHaveBeenCalledWith(stringFlag, defaultStringValue, {}, {}); + expect(MOCK_PROVIDER.resolveStringEvaluation).toHaveBeenCalledWith(stringFlag, defaultStringValue, {}); }); }); @@ -170,7 +170,7 @@ describe(OpenFeatureClient.name, () => { expect(numberDetails.value).toEqual(NUMBER_VALUE); expect(numberDetails.variant).toEqual(NUMBER_VARIANT); - expect(MOCK_PROVIDER.resolveNumberEvaluation).toHaveBeenCalledWith(numberFlag, defaultNumberValue, {}, {}); + expect(MOCK_PROVIDER.resolveNumberEvaluation).toHaveBeenCalledWith(numberFlag, defaultNumberValue, {}); }); }); @@ -182,7 +182,7 @@ describe(OpenFeatureClient.name, () => { expect(objectDetails.value).toEqual(OBJECT_VALUE); expect(objectDetails.variant).toEqual(OBJECT_VARIANT); - expect(MOCK_PROVIDER.resolveObjectEvaluation).toHaveBeenCalledWith(objectFlag, defaultObjectFlag, {}, {}); + expect(MOCK_PROVIDER.resolveObjectEvaluation).toHaveBeenCalledWith(objectFlag, defaultObjectFlag, {}); }); }); }); @@ -303,8 +303,7 @@ describe(OpenFeatureClient.name, () => { expect(nonTransformingProvider.resolveBooleanEvaluation).toHaveBeenCalledWith( flagKey, defaultValue, - expect.objectContaining({ transformed: false }), - expect.anything() + expect.objectContaining({ transformed: false }) ); }); }); @@ -337,8 +336,7 @@ describe(OpenFeatureClient.name, () => { expect.anything(), expect.objectContaining({ targetingKey: TARGETING_KEY, - }), - expect.anything() + }) ); }); }); @@ -363,8 +361,7 @@ describe(OpenFeatureClient.name, () => { expect.anything(), expect.objectContaining({ ...context, - }), - expect.anything() + }) ); }); }); @@ -406,8 +403,7 @@ describe(OpenFeatureClient.name, () => { ...clientContext, ...invocationContext, ...beforeHookContext, - }), - expect.anything() + }) ); }); }); diff --git a/test/hooks.spec.ts b/test/hooks.spec.ts index ff7881edd..fd0b00c97 100644 --- a/test/hooks.spec.ts +++ b/test/hooks.spec.ts @@ -169,8 +169,7 @@ describe('Hooks', () => { // ensure property was added by the time the flag resolution occurred. expect.objectContaining({ beforeRan: true, - }), - expect.anything() + }) ); }); }); @@ -254,8 +253,7 @@ describe('Hooks', () => { [invocationProp434]: true, [invocationPropToOverwrite434]: true, [hookProp434]: true, - }), - expect.anything() + }) ); }); }); @@ -939,7 +937,7 @@ describe('Hooks', () => { it('should be awaited, run in order', (done) => { OpenFeature.setProvider(MOCK_PROVIDER); - const asyncBeforeErroFinally = { + const asyncBeforeErrorFinally = { before: jest.fn(() => { return new Promise((resolve, reject) => setTimeout(() => { @@ -949,7 +947,7 @@ describe('Hooks', () => { }), error: jest.fn(() => { try { - expect(asyncBeforeErroFinally.before).toHaveBeenCalled(); + expect(asyncBeforeErrorFinally.before).toHaveBeenCalled(); } catch (err) { done(err); } @@ -957,7 +955,7 @@ describe('Hooks', () => { }), finally: () => { try { - expect(asyncBeforeErroFinally.error).toHaveBeenCalled(); + expect(asyncBeforeErrorFinally.error).toHaveBeenCalled(); done(); } catch (err) { done(err); @@ -966,7 +964,7 @@ describe('Hooks', () => { }; client.getBooleanValue(FLAG_KEY, false, undefined, { - hooks: [asyncBeforeErroFinally], + hooks: [asyncBeforeErrorFinally], }); }); });