|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +import * as chai from "chai"; |
| 5 | +import * as chaiAsPromised from "chai-as-promised"; |
| 6 | +chai.use(chaiAsPromised); |
| 7 | +const expect = chai.expect; |
| 8 | +import { createMockedConnectionString, createMockedFeatureFlag, HttpRequestHeadersPolicy, sleepInMs } from "./utils/testHelper"; |
| 9 | +import { mockServerEndpoint, startMockServer, closeMockServer } from "./utils/integrationTestHelper"; |
| 10 | +import { load } from "./exportedApi"; |
| 11 | + |
| 12 | +describe("integration test", function () { |
| 13 | + this.timeout(15000); |
| 14 | + |
| 15 | + const headerPolicy = new HttpRequestHeadersPolicy(); |
| 16 | + const position: "perCall" | "perRetry" = "perCall"; |
| 17 | + const clientOptions = { |
| 18 | + retryOptions: { |
| 19 | + maxRetries: 0 // save time |
| 20 | + }, |
| 21 | + allowInsecureConnection: true, |
| 22 | + additionalPolicies: [{ |
| 23 | + policy: headerPolicy, |
| 24 | + position |
| 25 | + }] |
| 26 | + }; |
| 27 | + |
| 28 | + it("should have request type in correlation-context header if feature flags use feature filters", async () => { |
| 29 | + // We are using self-signed certificate |
| 30 | + process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; |
| 31 | + |
| 32 | + startMockServer([ |
| 33 | + createMockedFeatureFlag("Alpha_1", { conditions: { client_filters: [ { name: "Microsoft.TimeWindow" } ] } }), |
| 34 | + createMockedFeatureFlag("Alpha_2", { conditions: { client_filters: [ { name: "Microsoft.Targeting" } ] } }), |
| 35 | + createMockedFeatureFlag("Alpha_3", { conditions: { client_filters: [ { name: "CustomFilter" } ] } }) |
| 36 | + ]); |
| 37 | + |
| 38 | + const settings = await load(createMockedConnectionString(mockServerEndpoint), { |
| 39 | + clientOptions, |
| 40 | + featureFlagOptions: { |
| 41 | + enabled: true, |
| 42 | + selectors: [ {keyFilter: "*"} ], |
| 43 | + refresh: { |
| 44 | + enabled: true, |
| 45 | + refreshIntervalInMs: 1000 |
| 46 | + } |
| 47 | + } |
| 48 | + }); |
| 49 | + await sleepInMs(1000 + 1); |
| 50 | + try { |
| 51 | + await settings.refresh(); |
| 52 | + } catch (e) { /* empty */ } |
| 53 | + expect(headerPolicy.headers).not.undefined; |
| 54 | + const correlationContext = headerPolicy.headers.get("Correlation-Context"); |
| 55 | + expect(correlationContext).not.undefined; |
| 56 | + expect(correlationContext.includes("RequestType=Watch")).eq(true); |
| 57 | + expect(correlationContext.includes("Filter=CSTM+TIME+TRGT")).eq(true); |
| 58 | + |
| 59 | + closeMockServer(); |
| 60 | + }); |
| 61 | +}); |
0 commit comments