Skip to content

Commit 855e909

Browse files
add more testcases
1 parent 667f721 commit 855e909

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"dev": "rollup --config --watch",
2626
"lint": "eslint src/ test/",
2727
"fix-lint": "eslint src/ test/ --fix",
28-
"test": "mocha out/test/*.test.{js,cjs,mjs} --parallel"
28+
"test": "mocha out/test/featureFlag.test.{js,cjs,mjs} --parallel"
2929
},
3030
"repository": {
3131
"type": "git",

src/AzureAppConfigurationImpl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,9 @@ function getValidFeatureFlagSelectors(selectors?: SettingSelector[]): SettingSel
931931
return [{ keyFilter: `${featureFlagPrefix}${KeyFilter.Any}`, labelFilter: LabelFilter.Null }];
932932
}
933933
selectors.forEach(selector => {
934-
selector.keyFilter = `${featureFlagPrefix}${selector.keyFilter}`;
934+
if (selector.keyFilter) {
935+
selector.keyFilter = `${featureFlagPrefix}${selector.keyFilter}`;
936+
}
935937
});
936938
return getValidSettingSelectors(selectors);
937939
}

test/featureFlag.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as chai from "chai";
55
import * as chaiAsPromised from "chai-as-promised";
66
import { featureFlagContentType } from "@azure/app-configuration";
77
import { load } from "./exportedApi.js";
8-
import { MAX_TIME_OUT, createMockedConnectionString, createMockedEndpoint, createMockedFeatureFlag, createMockedKeyValue, mockAppConfigurationClientListConfigurationSettings, restoreMocks } from "./utils/testHelper.js";
8+
import { MAX_TIME_OUT, mockAppConfigurationClientGetSnapshot, mockAppConfigurationClientListConfigurationSettingsForSnapshot, createMockedConnectionString, createMockedEndpoint, createMockedFeatureFlag, createMockedKeyValue, mockAppConfigurationClientListConfigurationSettings, restoreMocks } from "./utils/testHelper.js";
99
chai.use(chaiAsPromised);
1010
const expect = chai.expect;
1111

@@ -337,4 +337,25 @@ describe("feature flags", function () {
337337
expect(featureFlag.telemetry.metadata.ETag).equals("ETag");
338338
expect(featureFlag.telemetry.metadata.FeatureFlagReference).equals(`${createMockedEndpoint()}/kv/.appconfig.featureflag/Telemetry_2?label=Test`);
339339
});
340+
341+
it("should load feature flags from snapshot", async () => {
342+
const snapshotName = "Test";
343+
mockAppConfigurationClientGetSnapshot(snapshotName, {compositionType: "key"});
344+
mockAppConfigurationClientListConfigurationSettingsForSnapshot(snapshotName, [[createMockedFeatureFlag("TestFeature", { enabled: true })]]);
345+
const connectionString = createMockedConnectionString();
346+
const settings = await load(connectionString, {
347+
featureFlagOptions: {
348+
enabled: true,
349+
selectors: [ { snapshotName: snapshotName } ]
350+
}
351+
});
352+
expect(settings).not.undefined;
353+
expect(settings.get("feature_management")).not.undefined;
354+
const featureFlags = settings.get<any>("feature_management").feature_flags;
355+
expect((featureFlags as []).length).equals(1);
356+
const featureFlag = featureFlags[0];
357+
expect(featureFlag.id).equals("TestFeature");
358+
expect(featureFlag.enabled).equals(true);
359+
restoreMocks();
360+
});
340361
});

test/load.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ describe("load", function () {
122122
return expect(load("invalid-endpoint-url", credential)).eventually.rejectedWith("Invalid URL");
123123
});
124124

125+
it("should throw error given invalid selector", async () => {
126+
const connectionString = createMockedConnectionString();
127+
return expect(load(connectionString, {
128+
selectors: [{
129+
labelFilter: "\0"
130+
}]
131+
})).eventually.rejectedWith("Key filter cannot be null or empty.");
132+
});
133+
134+
it("should throw error given invalid snapshot selector", async () => {
135+
const connectionString = createMockedConnectionString();
136+
return expect(load(connectionString, {
137+
selectors: [{
138+
snapshotName: "Test",
139+
labelFilter: "\0"
140+
}]
141+
})).eventually.rejectedWith("Key or label filter should not be used for a snapshot.");
142+
});
143+
125144
it("should not include feature flags directly in the settings", async () => {
126145
const connectionString = createMockedConnectionString();
127146
const settings = await load(connectionString);
@@ -419,7 +438,7 @@ describe("load", function () {
419438
}).to.throw("Invalid separator '%'. Supported values: '.', ',', ';', '-', '_', '__', '/', ':'.");
420439
});
421440

422-
it("should load from snapshot", async () => {
441+
it("should load key values from snapshot", async () => {
423442
const snapshotName = "Test";
424443
mockAppConfigurationClientGetSnapshot(snapshotName, {compositionType: "key"});
425444
mockAppConfigurationClientListConfigurationSettingsForSnapshot(snapshotName, [[{key: "TestKey", value: "TestValue"}].map(createMockedKeyValue)]);

0 commit comments

Comments
 (0)