@@ -5,9 +5,11 @@ import * as chai from "chai";
55import * as chaiAsPromised from "chai-as-promised" ;
66chai . use ( chaiAsPromised ) ;
77const expect = chai . expect ;
8- import { createMockedConnectionString , createMockedKeyValue , createMockedTokenCredential , mockAppConfigurationClientListConfigurationSettings , restoreMocks , HttpRequestHeadersPolicy , sleepInMs } from "./utils/testHelper.js" ;
8+ import { createMockedConnectionString , createMockedKeyValue , createMockedFeatureFlag , createMockedTokenCredential , mockAppConfigurationClientListConfigurationSettings , restoreMocks , HttpRequestHeadersPolicy , sleepInMs } from "./utils/testHelper.js" ;
99import { load } from "./exportedApi.js" ;
1010
11+ const CORRELATION_CONTEXT_HEADER_NAME = "Correlation-Context" ;
12+
1113describe ( "request tracing" , function ( ) {
1214 this . timeout ( 15000 ) ;
1315
@@ -136,6 +138,44 @@ describe("request tracing", function () {
136138 restoreMocks ( ) ;
137139 } ) ;
138140
141+ it ( "should have filter type in correlation-context header if feature flags use feature filters" , async ( ) => {
142+ let correlationContext : string = "" ;
143+ const listKvCallback = ( listOptions ) => {
144+ correlationContext = listOptions ?. requestOptions ?. customHeaders [ CORRELATION_CONTEXT_HEADER_NAME ] ?? "" ;
145+ } ;
146+
147+ mockAppConfigurationClientListConfigurationSettings ( [ [
148+ createMockedFeatureFlag ( "Alpha_1" , { conditions : { client_filters : [ { name : "Microsoft.TimeWindow" } ] } } ) ,
149+ createMockedFeatureFlag ( "Alpha_2" , { conditions : { client_filters : [ { name : "Microsoft.Targeting" } ] } } ) ,
150+ createMockedFeatureFlag ( "Alpha_3" , { conditions : { client_filters : [ { name : "CustomFilter" } ] } } )
151+ ] ] , listKvCallback ) ;
152+
153+ const settings = await load ( createMockedConnectionString ( fakeEndpoint ) , {
154+ featureFlagOptions : {
155+ enabled : true ,
156+ selectors : [ { keyFilter : "*" } ] ,
157+ refresh : {
158+ enabled : true ,
159+ refreshIntervalInMs : 1000
160+ }
161+ }
162+ } ) ;
163+
164+ expect ( correlationContext ) . not . undefined ;
165+ expect ( correlationContext ?. includes ( "RequestType=Startup" ) ) . eq ( true ) ;
166+
167+ await sleepInMs ( 1000 + 1 ) ;
168+ try {
169+ await settings . refresh ( ) ;
170+ } catch ( e ) { /* empty */ }
171+ expect ( headerPolicy . headers ) . not . undefined ;
172+ expect ( correlationContext ) . not . undefined ;
173+ expect ( correlationContext ?. includes ( "RequestType=Watch" ) ) . eq ( true ) ;
174+ expect ( correlationContext ?. includes ( "Filter=CSTM+TIME+TRGT" ) ) . eq ( true ) ;
175+
176+ restoreMocks ( ) ;
177+ } ) ;
178+
139179 describe ( "request tracing in Web Worker environment" , ( ) => {
140180 let originalNavigator ;
141181 let originalWorkerNavigator ;
0 commit comments