@@ -353,6 +353,30 @@ describe('FlagsmithProvider', () => {
353353 ) ;
354354 expect ( config . fetch ) . toHaveBeenCalledTimes ( 3 ) ;
355355 } ) ;
356+
357+ it ( 'should set new traits when the context is updated' , async ( ) => {
358+ const config = defaultConfig ( ) ;
359+ const provider = new FlagsmithClientProvider ( {
360+ logger,
361+ ...config ,
362+ } ) ;
363+ await OpenFeature . setProviderAndWait ( provider ) ;
364+ await OpenFeature . setContext ( { targetingKey : 'first' , traitA : 'a' } ) ;
365+ expect ( config . fetch ) . toHaveBeenCalledWith (
366+ `${ provider . flagsmithClient . getState ( ) . api } identities/` ,
367+ expect . objectContaining ( {
368+ body : JSON . stringify ( { identifier : 'first' , traits : [ { trait_key : 'traitA' , trait_value : 'a' } ] } ) ,
369+ } ) ,
370+ ) ;
371+ await OpenFeature . setContext ( { targetingKey : 'second' , traitB : 'b' } ) ;
372+ expect ( config . fetch ) . toHaveBeenCalledWith (
373+ `${ provider . flagsmithClient . getState ( ) . api } identities/` ,
374+ expect . objectContaining ( {
375+ body : JSON . stringify ( { identifier : 'second' , traits : [ { trait_key : 'traitB' , trait_value : 'b' } ] } ) ,
376+ } ) ,
377+ ) ;
378+ } ) ;
379+
356380 it ( 'should initialize with the targeting key and traits when passed to initialize' , async ( ) => {
357381 const targetingKey = 'test' ;
358382 const traits = { foo : 'bar' , example : 123 } ;
0 commit comments