11import type { Config , FlagdProviderOptions } from './configuration' ;
22import { getConfig } from './configuration' ;
33import { DEFAULT_MAX_CACHE_SIZE } from './constants' ;
4+ import { EvaluationContext } from "@openfeature/server-sdk" ;
45
56describe ( 'Configuration' , ( ) => {
67 const OLD_ENV = process . env ;
@@ -20,6 +21,7 @@ describe('Configuration', () => {
2021 resolverType : 'rpc' ,
2122 selector : '' ,
2223 deadlineMs : 500 ,
24+ contextEnricher : expect . any ( Function ) ,
2325 } ) ;
2426 } ) ;
2527
@@ -46,7 +48,7 @@ describe('Configuration', () => {
4648 process . env [ 'FLAGD_OFFLINE_FLAG_SOURCE_PATH' ] = offlineFlagSourcePath ;
4749 process . env [ 'FLAGD_DEFAULT_AUTHORITY' ] = defaultAuthority ;
4850
49- expect ( getConfig ( ) ) . toStrictEqual ( {
51+ expect ( getConfig ( ) ) . toEqual ( expect . objectContaining ( {
5052 host,
5153 port,
5254 tls,
@@ -58,10 +60,21 @@ describe('Configuration', () => {
5860 offlineFlagSourcePath,
5961 defaultAuthority,
6062 deadlineMs : 500 ,
61- } ) ;
63+ } ) ) ;
64+ } ) ;
65+
66+ it ( 'should override context enricher' , ( ) => {
67+ const contextEnricher = ( syncContext : { [ key : string ] : string } | null ) => { return { ...syncContext , extraKey : "extraValue" } as EvaluationContext } ;
68+
69+ expect ( getConfig ( { contextEnricher } ) . contextEnricher ( { } ) ) . toEqual ( { extraKey : "extraValue" } ) ;
70+ } ) ;
71+
72+ it ( 'should return identity function' , ( ) => {
73+ expect ( getConfig ( ) . contextEnricher ( { } ) ) . toStrictEqual ( { } ) ;
6274 } ) ;
6375
6476 it ( 'should use incoming options over defaults and environment variable' , ( ) => {
77+ const contextEnricher = ( syncContext : { [ key : string ] : string } | null ) => { return { ...syncContext , extraKey : "extraValue" } as EvaluationContext } ;
6578 const options : FlagdProviderOptions = {
6679 host : 'test' ,
6780 port : 3000 ,
@@ -72,6 +85,7 @@ describe('Configuration', () => {
7285 selector : '' ,
7386 defaultAuthority : '' ,
7487 deadlineMs : 500 ,
88+ contextEnricher : contextEnricher
7589 } ;
7690
7791 process . env [ 'FLAGD_HOST' ] = 'override' ;
0 commit comments