Skip to content

Commit

Permalink
fix: update the client to conform to the provider interface (#187)
Browse files Browse the repository at this point in the history
The resolve argument in the evaluation method was still using evaluation options.

Signed-off-by: Michael Beemer <[email protected]>
  • Loading branch information
beeme1mr authored Aug 26, 2022
1 parent b66171f commit f1edb29
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
9 changes: 2 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,7 @@ export class OpenFeatureClient implements Client {

private async evaluate<T extends FlagValue>(
flagKey: string,
resolver: (
flagKey: string,
defaultValue: T,
context: EvaluationContext,
options: FlagEvaluationOptions | undefined
) => Promise<ResolutionDetails<T>>,
resolver: (flagKey: string, defaultValue: T, context: EvaluationContext) => Promise<ResolutionDetails<T>>,
defaultValue: T,
flagType: FlagValueType,
invocationContext: EvaluationContext = {},
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 12 additions & 16 deletions test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
});
});

Expand All @@ -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, {});
});
});

Expand All @@ -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, {});
});
});

Expand All @@ -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, {});
});
});
});
Expand All @@ -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, {});
});
});

Expand All @@ -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, {});
});
});

Expand All @@ -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, {});
});
});

Expand All @@ -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, {});
});
});
});
Expand Down Expand Up @@ -303,8 +303,7 @@ describe(OpenFeatureClient.name, () => {
expect(nonTransformingProvider.resolveBooleanEvaluation).toHaveBeenCalledWith(
flagKey,
defaultValue,
expect.objectContaining({ transformed: false }),
expect.anything()
expect.objectContaining({ transformed: false })
);
});
});
Expand Down Expand Up @@ -337,8 +336,7 @@ describe(OpenFeatureClient.name, () => {
expect.anything(),
expect.objectContaining({
targetingKey: TARGETING_KEY,
}),
expect.anything()
})
);
});
});
Expand All @@ -363,8 +361,7 @@ describe(OpenFeatureClient.name, () => {
expect.anything(),
expect.objectContaining({
...context,
}),
expect.anything()
})
);
});
});
Expand Down Expand Up @@ -406,8 +403,7 @@ describe(OpenFeatureClient.name, () => {
...clientContext,
...invocationContext,
...beforeHookContext,
}),
expect.anything()
})
);
});
});
Expand Down
14 changes: 6 additions & 8 deletions test/hooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ describe('Hooks', () => {
// ensure property was added by the time the flag resolution occurred.
expect.objectContaining({
beforeRan: true,
}),
expect.anything()
})
);
});
});
Expand Down Expand Up @@ -254,8 +253,7 @@ describe('Hooks', () => {
[invocationProp434]: true,
[invocationPropToOverwrite434]: true,
[hookProp434]: true,
}),
expect.anything()
})
);
});
});
Expand Down Expand Up @@ -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<EvaluationContext>((resolve, reject) =>
setTimeout(() => {
Expand All @@ -949,15 +947,15 @@ describe('Hooks', () => {
}),
error: jest.fn(() => {
try {
expect(asyncBeforeErroFinally.before).toHaveBeenCalled();
expect(asyncBeforeErrorFinally.before).toHaveBeenCalled();
} catch (err) {
done(err);
}
return Promise.resolve();
}),
finally: () => {
try {
expect(asyncBeforeErroFinally.error).toHaveBeenCalled();
expect(asyncBeforeErrorFinally.error).toHaveBeenCalled();
done();
} catch (err) {
done(err);
Expand All @@ -966,7 +964,7 @@ describe('Hooks', () => {
};

client.getBooleanValue(FLAG_KEY, false, undefined, {
hooks: [asyncBeforeErroFinally],
hooks: [asyncBeforeErrorFinally],
});
});
});
Expand Down

0 comments on commit f1edb29

Please sign in to comment.