33
44import * as chai from "chai" ;
55import * as chaiAsPromised from "chai-as-promised" ;
6+ import { featureFlagContentType } from "@azure/app-configuration" ;
67import { load } from "./exportedApi.js" ;
78import { MAX_TIME_OUT , createMockedConnectionString , createMockedEndpoint , createMockedFeatureFlag , createMockedKeyValue , mockAppConfigurationClientListConfigurationSettings , restoreMocks } from "./utils/testHelper.js" ;
89chai . use ( chaiAsPromised ) ;
@@ -49,9 +50,9 @@ const mockedKVs = [{
4950} , {
5051 key : ".appconfig.featureflag/variant" ,
5152 value : sampleVariantValue ,
52- contentType : "application/vnd.microsoft.appconfig.ff+json;charset=utf-8" ,
53+ contentType : featureFlagContentType ,
5354} ] . map ( createMockedKeyValue ) . concat ( [
54- createMockedFeatureFlag ( "Beta " , { enabled : true } ) ,
55+ createMockedFeatureFlag ( "FlagWithTestLabel " , { enabled : true } , { label : "Test" } ) ,
5556 createMockedFeatureFlag ( "Alpha_1" , { enabled : true } ) ,
5657 createMockedFeatureFlag ( "Alpha_2" , { enabled : false } ) ,
5758 createMockedFeatureFlag ( "Telemetry_1" , { enabled : true , telemetry : { enabled : true } } , { etag : "ETag" } ) ,
@@ -213,15 +214,22 @@ describe("feature flags", function () {
213214 const connectionString = createMockedConnectionString ( ) ;
214215 const settings = await load ( connectionString , {
215216 featureFlagOptions : {
216- enabled : true ,
217- selectors : [ {
218- keyFilter : "*"
219- } ]
217+ enabled : true
220218 }
221219 } ) ;
222220 expect ( settings ) . not . undefined ;
223221 expect ( settings . get ( "feature_management" ) ) . not . undefined ;
224222 expect ( settings . get < any > ( "feature_management" ) . feature_flags ) . not . undefined ;
223+ // it should only load feature flags with no label by default
224+ expect ( ( settings . get < any > ( "feature_management" ) . feature_flags as any [ ] ) . find ( ff => ff . id === "FlagWithTestLabel" ) ) . to . be . undefined ;
225+
226+ const settings2 = await load ( connectionString , {
227+ featureFlagOptions : {
228+ enabled : true ,
229+ selectors : [ { keyFilter : "*" , labelFilter : "Test" } ]
230+ }
231+ } ) ;
232+ expect ( ( settings2 . get < any > ( "feature_management" ) . feature_flags as any [ ] ) . find ( ff => ff . id === "FlagWithTestLabel" ) ) . not . undefined ;
225233 } ) ;
226234
227235 it ( "should not load feature flags if disabled" , async ( ) => {
@@ -242,15 +250,6 @@ describe("feature flags", function () {
242250 expect ( settings . get ( "feature_management" ) ) . undefined ;
243251 } ) ;
244252
245- it ( "should throw error if selectors not specified" , async ( ) => {
246- const connectionString = createMockedConnectionString ( ) ;
247- return expect ( load ( connectionString , {
248- featureFlagOptions : {
249- enabled : true
250- }
251- } ) ) . eventually . rejectedWith ( "Feature flag selectors must be provided." ) ;
252- } ) ;
253-
254253 it ( "should load feature flags with custom selector" , async ( ) => {
255254 const connectionString = createMockedConnectionString ( ) ;
256255 const settings = await load ( connectionString , {
0 commit comments