Skip to content

Commit 09934da

Browse files
authored
chore: improve merging test to include the before hook (#179)
Signed-off-by: Michael Beemer <[email protected]>
1 parent 8dcba09 commit 09934da

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

test/client.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ describe(OpenFeatureClient.name, () => {
370370
});
371371

372372
describe('3.2.1, 3.2.2', () => {
373-
it('Evaluation context MUST be merged in the order: API (global) -> client -> invocation, with duplicate values being overwritten.', async () => {
373+
it('Evaluation context MUST be merged in the order: API (global; lowest precedence) -> client -> invocation -> before hooks (highest precedence), with duplicate values being overwritten.', async () => {
374374
const flagKey = 'some-other-flag';
375375
const defaultValue = false;
376376
const globalContext: EvaluationContext = {
@@ -384,12 +384,18 @@ describe(OpenFeatureClient.name, () => {
384384
};
385385
const invocationContext: EvaluationContext = {
386386
invocationContextValue: 'ghi',
387+
invocationContextValueToOverwrite: 'xxx', // should be overwritten
387388
clientContextValueToOverwrite: '456',
388389
};
390+
const beforeHookContext: EvaluationContext = {
391+
invocationContextValueToOverwrite: '789',
392+
beforeHookContextValue: 'jkl',
393+
};
389394

390395
OpenFeature.setProvider(provider);
391396
OpenFeature.context = globalContext;
392397
const client = OpenFeature.getClient('contextual', 'test', clientContext);
398+
client.addHooks({ before: () => beforeHookContext });
393399
await client.getBooleanValue(flagKey, defaultValue, invocationContext);
394400
expect(provider.resolveBooleanEvaluation).toHaveBeenCalledWith(
395401
expect.anything(),
@@ -399,6 +405,7 @@ describe(OpenFeatureClient.name, () => {
399405
...globalContext,
400406
...clientContext,
401407
...invocationContext,
408+
...beforeHookContext,
402409
}),
403410
expect.anything()
404411
);

0 commit comments

Comments
 (0)