@@ -16,7 +16,7 @@ import FetchHttpClient, {
16
16
IUniversalFlagConfigResponse ,
17
17
} from './http-client' ;
18
18
import { StoreBackedConfiguration } from './i-configuration' ;
19
- import { BanditParameters , BanditVariation , Flag } from './interfaces' ;
19
+ import { BanditParameters , BanditVariation , Flag , VariationType } from './interfaces' ;
20
20
21
21
describe ( 'ConfigurationRequestor' , ( ) => {
22
22
let flagStore : IConfigurationStore < Flag > ;
@@ -588,5 +588,72 @@ describe('ConfigurationRequestor', () => {
588
588
expect ( fetchSpy . mock . calls . length ) . toBe ( 1 ) ;
589
589
} ) ;
590
590
} ) ;
591
+
592
+ describe ( 'IConfigurationStore updates' , ( ) => {
593
+ it ( 'should update configuration when stores are changed' , async ( ) => {
594
+ // Create new stores
595
+ const newFlagStore = new MemoryOnlyConfigurationStore < Flag > ( ) ;
596
+ const newBanditVariationStore = new MemoryOnlyConfigurationStore < BanditVariation [ ] > ( ) ;
597
+ const newBanditModelStore = new MemoryOnlyConfigurationStore < BanditParameters > ( ) ;
598
+
599
+ // Add a test flag to the new flag store
600
+ await newFlagStore . setEntries ( {
601
+ 'test-flag' : {
602
+ key : 'test-flag' ,
603
+ enabled : true ,
604
+ variationType : VariationType . STRING ,
605
+ variations : {
606
+ control : { key : 'control' , value : 'control-value' } ,
607
+ treatment : { key : 'treatment' , value : 'treatment-value' } ,
608
+ } ,
609
+ allocations : [
610
+ {
611
+ key : 'allocation-1' ,
612
+ rules : [ ] ,
613
+ splits : [
614
+ {
615
+ shards : [ { salt : '' , ranges : [ { start : 0 , end : 10000 } ] } ] ,
616
+ variationKey : 'treatment' ,
617
+ } ,
618
+ ] ,
619
+ doLog : true ,
620
+ } ,
621
+ ] ,
622
+ totalShards : 10000 ,
623
+ } ,
624
+ } ) ;
625
+
626
+ await newBanditModelStore . setEntries ( {
627
+ 'test-bandit' : {
628
+ banditKey : 'test-bandt' ,
629
+ modelVersion : 'v123' ,
630
+ modelName : 'falcon' ,
631
+ modelData : {
632
+ coefficients : { } ,
633
+ gamma : 0 ,
634
+ defaultActionScore : 0 ,
635
+ actionProbabilityFloor : 0 ,
636
+ } ,
637
+ } ,
638
+ } ) ;
639
+
640
+ // Get the configuration and verify it has the test flag
641
+ const initialConfig = configurationRequestor . getConfiguration ( ) ;
642
+ expect ( initialConfig . getFlagKeys ( ) ) . toEqual ( [ ] ) ;
643
+ expect ( Object . keys ( initialConfig . getBandits ( ) ) ) . toEqual ( [ ] ) ;
644
+
645
+ // Update the stores
646
+ configurationRequestor . setConfigurationStores (
647
+ newFlagStore ,
648
+ newBanditVariationStore ,
649
+ newBanditModelStore ,
650
+ ) ;
651
+
652
+ // Get the configuration and verify it has the test flag
653
+ const config = configurationRequestor . getConfiguration ( ) ;
654
+ expect ( config . getFlagKeys ( ) ) . toEqual ( [ 'test-flag' ] ) ;
655
+ expect ( Object . keys ( config . getBandits ( ) ) ) . toEqual ( [ 'test-bandit' ] ) ;
656
+ } ) ;
657
+ } ) ;
591
658
} ) ;
592
659
} ) ;
0 commit comments