@@ -15,25 +15,117 @@ describe("Local Overrides", () => {
1515 sdkType : "common" ,
1616 sdkVersion : "1.0.0"
1717 } ;
18+
19+ const overrideMap = {
20+ enabledFeature : true ,
21+ disabledFeature : false ,
22+ intSetting : 5 ,
23+ doubleSetting : 3.14 ,
24+ stringSetting : "test"
25+ } ;
26+
1827 const options : AutoPollOptions = new AutoPollOptions ( "localhost" , "common" , "1.0.0" , {
1928 flagOverrides : {
20- dataSource : new MapOverrideDataSource ( {
21- enabledFeature : true ,
22- disabledFeature : false ,
23- intSetting : 5 ,
24- doubleSetting : 3.14 ,
25- stringSetting : "test"
26- } ) ,
29+ dataSource : new MapOverrideDataSource ( overrideMap ) ,
2730 behaviour : OverrideBehaviour . LocalOnly
2831 }
2932 } , null ) ;
3033 const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
3134
32- assert . equal ( await client . getValueAsync ( "enabledFeature" , false ) , true ) ;
33- assert . equal ( await client . getValueAsync ( "disabledFeature" , true ) , false ) ;
34- assert . equal ( await client . getValueAsync ( "intSetting" , 0 ) , 5 ) ;
35- assert . equal ( await client . getValueAsync ( "doubleSetting" , 0 ) , 3.14 ) ;
36- assert . equal ( await client . getValueAsync ( "stringSetting" , "" ) , "test" ) ;
35+ assert . equal ( await client . getValueAsync ( "enabledFeature" , null ) , true ) ;
36+ assert . equal ( await client . getValueAsync ( "disabledFeature" , null ) , false ) ;
37+ assert . equal ( await client . getValueAsync ( "intSetting" , null ) , 5 ) ;
38+ assert . equal ( await client . getValueAsync ( "doubleSetting" , null ) , 3.14 ) ;
39+ assert . equal ( await client . getValueAsync ( "stringSetting" , null ) , "test" ) ;
40+
41+ overrideMap . disabledFeature = true ;
42+ overrideMap . intSetting = - 5 ;
43+
44+ assert . equal ( await client . getValueAsync ( "enabledFeature" , null ) , true ) ;
45+ assert . equal ( await client . getValueAsync ( "disabledFeature" , null ) , false ) ;
46+ assert . equal ( await client . getValueAsync ( "intSetting" , null ) , 5 ) ;
47+ assert . equal ( await client . getValueAsync ( "doubleSetting" , null ) , 3.14 ) ;
48+ assert . equal ( await client . getValueAsync ( "stringSetting" , null ) , "test" ) ;
49+ } ) ;
50+
51+ it ( "Values from map - LocalOnly - watch changes - async" , async ( ) => {
52+ const configCatKernel : FakeConfigCatKernel = {
53+ configFetcher : new FakeConfigFetcherBase ( "{\"f\": { \"fakeKey\": { \"v\": false, \"p\": [], \"r\": [] } } }" ) ,
54+ sdkType : "common" ,
55+ sdkVersion : "1.0.0"
56+ } ;
57+
58+ const overrideMap = {
59+ enabledFeature : true ,
60+ disabledFeature : false ,
61+ intSetting : 5 ,
62+ doubleSetting : 3.14 ,
63+ stringSetting : "test"
64+ } ;
65+
66+ const options : AutoPollOptions = new AutoPollOptions ( "localhost" , "common" , "1.0.0" , {
67+ flagOverrides : {
68+ dataSource : new MapOverrideDataSource ( overrideMap , true ) ,
69+ behaviour : OverrideBehaviour . LocalOnly
70+ }
71+ } , null ) ;
72+ const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
73+
74+ assert . equal ( await client . getValueAsync ( "enabledFeature" , null ) , true ) ;
75+ assert . equal ( await client . getValueAsync ( "disabledFeature" , null ) , false ) ;
76+ assert . equal ( await client . getValueAsync ( "intSetting" , null ) , 5 ) ;
77+ assert . equal ( await client . getValueAsync ( "doubleSetting" , null ) , 3.14 ) ;
78+ assert . equal ( await client . getValueAsync ( "stringSetting" , null ) , "test" ) ;
79+
80+ overrideMap . disabledFeature = true ;
81+ overrideMap . intSetting = - 5 ;
82+
83+ assert . equal ( await client . getValueAsync ( "enabledFeature" , null ) , true ) ;
84+ assert . equal ( await client . getValueAsync ( "disabledFeature" , null ) , true ) ;
85+ assert . equal ( await client . getValueAsync ( "intSetting" , null ) , - 5 ) ;
86+ assert . equal ( await client . getValueAsync ( "doubleSetting" , null ) , 3.14 ) ;
87+ assert . equal ( await client . getValueAsync ( "stringSetting" , null ) , "test" ) ;
88+ } ) ;
89+
90+ it ( "Values from map - LocalOnly - watch changes - sync" , async ( ) => {
91+ const configCatKernel : FakeConfigCatKernel = {
92+ configFetcher : new FakeConfigFetcherBase ( "{\"f\": { \"fakeKey\": { \"v\": false, \"p\": [], \"r\": [] } } }" ) ,
93+ sdkType : "common" ,
94+ sdkVersion : "1.0.0"
95+ } ;
96+
97+ const overrideMap = {
98+ enabledFeature : true ,
99+ disabledFeature : false ,
100+ intSetting : 5 ,
101+ doubleSetting : 3.14 ,
102+ stringSetting : "test"
103+ } ;
104+
105+ const options : AutoPollOptions = new AutoPollOptions ( "localhost" , "common" , "1.0.0" , {
106+ flagOverrides : {
107+ dataSource : new MapOverrideDataSource ( overrideMap , true ) ,
108+ behaviour : OverrideBehaviour . LocalOnly
109+ }
110+ } , null ) ;
111+ const client : IConfigCatClient = new ConfigCatClient ( options , configCatKernel ) ;
112+
113+ let snapshot = client . snapshot ( ) ;
114+ assert . equal ( await snapshot . getValue ( "enabledFeature" , null ) , true ) ;
115+ assert . equal ( await snapshot . getValue ( "disabledFeature" , null ) , false ) ;
116+ assert . equal ( await snapshot . getValue ( "intSetting" , null ) , 5 ) ;
117+ assert . equal ( await snapshot . getValue ( "doubleSetting" , null ) , 3.14 ) ;
118+ assert . equal ( await snapshot . getValue ( "stringSetting" , null ) , "test" ) ;
119+
120+ overrideMap . disabledFeature = true ;
121+ overrideMap . intSetting = - 5 ;
122+
123+ snapshot = client . snapshot ( ) ;
124+ assert . equal ( await snapshot . getValue ( "enabledFeature" , null ) , true ) ;
125+ assert . equal ( await snapshot . getValue ( "disabledFeature" , null ) , true ) ;
126+ assert . equal ( await snapshot . getValue ( "intSetting" , null ) , - 5 ) ;
127+ assert . equal ( await snapshot . getValue ( "doubleSetting" , null ) , 3.14 ) ;
128+ assert . equal ( await snapshot . getValue ( "stringSetting" , null ) , "test" ) ;
37129 } ) ;
38130
39131 it ( "Values from map - LocalOverRemote" , async ( ) => {
0 commit comments