3
3
4
4
import * as chai from "chai" ;
5
5
import * as chaiAsPromised from "chai-as-promised" ;
6
+ import { featureFlagContentType } from "@azure/app-configuration" ;
6
7
import { load } from "./exportedApi.js" ;
7
8
import { MAX_TIME_OUT , createMockedConnectionString , createMockedEndpoint , createMockedFeatureFlag , createMockedKeyValue , mockAppConfigurationClientListConfigurationSettings , restoreMocks } from "./utils/testHelper.js" ;
8
9
chai . use ( chaiAsPromised ) ;
@@ -49,9 +50,9 @@ const mockedKVs = [{
49
50
} , {
50
51
key : ".appconfig.featureflag/variant" ,
51
52
value : sampleVariantValue ,
52
- contentType : "application/vnd.microsoft.appconfig.ff+json;charset=utf-8" ,
53
+ contentType : featureFlagContentType ,
53
54
} ] . map ( createMockedKeyValue ) . concat ( [
54
- createMockedFeatureFlag ( "Beta " , { enabled : true } ) ,
55
+ createMockedFeatureFlag ( "FlagWithTestLabel " , { enabled : true } , { label : "Test" } ) ,
55
56
createMockedFeatureFlag ( "Alpha_1" , { enabled : true } ) ,
56
57
createMockedFeatureFlag ( "Alpha_2" , { enabled : false } ) ,
57
58
createMockedFeatureFlag ( "Telemetry_1" , { enabled : true , telemetry : { enabled : true } } , { etag : "ETag" } ) ,
@@ -213,15 +214,22 @@ describe("feature flags", function () {
213
214
const connectionString = createMockedConnectionString ( ) ;
214
215
const settings = await load ( connectionString , {
215
216
featureFlagOptions : {
216
- enabled : true ,
217
- selectors : [ {
218
- keyFilter : "*"
219
- } ]
217
+ enabled : true
220
218
}
221
219
} ) ;
222
220
expect ( settings ) . not . undefined ;
223
221
expect ( settings . get ( "feature_management" ) ) . not . undefined ;
224
222
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 ;
225
233
} ) ;
226
234
227
235
it ( "should not load feature flags if disabled" , async ( ) => {
@@ -242,15 +250,6 @@ describe("feature flags", function () {
242
250
expect ( settings . get ( "feature_management" ) ) . undefined ;
243
251
} ) ;
244
252
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
-
254
253
it ( "should load feature flags with custom selector" , async ( ) => {
255
254
const connectionString = createMockedConnectionString ( ) ;
256
255
const settings = await load ( connectionString , {
0 commit comments