@@ -8,9 +8,48 @@ import { createMockedConnectionString, createMockedFeatureFlag, createMockedKeyV
88chai . use ( chaiAsPromised ) ;
99const expect = chai . expect ;
1010
11+ const sampleVariantValue = JSON . stringify ( {
12+ "id" : "variant" ,
13+ "description" : "" ,
14+ "enabled" : true ,
15+ "variants" : [
16+ {
17+ "name" : "Off" ,
18+ "configuration_value" : false
19+ } ,
20+ {
21+ "name" : "On" ,
22+ "configuration_value" : true
23+ }
24+ ] ,
25+ "allocation" : {
26+ "percentile" : [
27+ {
28+ "variant" : "Off" ,
29+ "from" : 0 ,
30+ "to" : 40
31+ } ,
32+ {
33+ "variant" : "On" ,
34+ "from" : 49 ,
35+ "to" : 100
36+ }
37+ ] ,
38+ "default_when_enabled" : "Off" ,
39+ "default_when_disabled" : "Off"
40+ } ,
41+ "telemetry" : {
42+ "enabled" : false
43+ }
44+ } ) ;
45+
1146const mockedKVs = [ {
1247 key : "app.settings.fontColor" ,
1348 value : "red" ,
49+ } , {
50+ key : ".appconfig.featureflag/variant" ,
51+ value : sampleVariantValue ,
52+ contentType : "application/vnd.microsoft.appconfig.ff+json;charset=utf-8" ,
1453} ] . map ( createMockedKeyValue ) . concat ( [
1554 createMockedFeatureFlag ( "Beta" , true ) ,
1655 createMockedFeatureFlag ( "Alpha_1" , true ) ,
@@ -86,4 +125,36 @@ describe("feature flags", function () {
86125 expect ( ( featureFlags as [ ] ) . length ) . equals ( 2 ) ;
87126 } ) ;
88127
128+ it ( "should parse variant" , async ( ) => {
129+ const connectionString = createMockedConnectionString ( ) ;
130+ const settings = await load ( connectionString , {
131+ featureFlagOptions : {
132+ enabled : true ,
133+ selectors : [ {
134+ keyFilter : "variant"
135+ } ]
136+ }
137+ } ) ;
138+ expect ( settings ) . not . undefined ;
139+ expect ( settings . get ( "feature_management" ) ) . not . undefined ;
140+ const featureFlags = settings . get < any > ( "feature_management" ) . feature_flags ;
141+ expect ( featureFlags ) . not . undefined ;
142+ expect ( ( featureFlags as [ ] ) . length ) . equals ( 1 ) ;
143+ const variant = featureFlags [ 0 ] ;
144+ expect ( variant ) . not . undefined ;
145+ expect ( variant . id ) . equals ( "variant" ) ;
146+ expect ( variant . variants ) . not . undefined ;
147+ expect ( variant . variants . length ) . equals ( 2 ) ;
148+ expect ( variant . variants [ 0 ] . configuration_value ) . equals ( false ) ;
149+ expect ( variant . variants [ 1 ] . configuration_value ) . equals ( true ) ;
150+ expect ( variant . allocation ) . not . undefined ;
151+ expect ( variant . allocation . percentile ) . not . undefined ;
152+ expect ( variant . allocation . percentile . length ) . equals ( 2 ) ;
153+ expect ( variant . allocation . percentile [ 0 ] . variant ) . equals ( "Off" ) ;
154+ expect ( variant . allocation . percentile [ 1 ] . variant ) . equals ( "On" ) ;
155+ expect ( variant . allocation . default_when_enabled ) . equals ( "Off" ) ;
156+ expect ( variant . allocation . default_when_disabled ) . equals ( "Off" ) ;
157+ expect ( variant . telemetry ) . not . undefined ;
158+ } ) ;
159+
89160} ) ;
0 commit comments