Skip to content

Commit 18d78f2

Browse files
[App Config] Add the prefix if not present for feature flags (Azure#15136)
* Add the prefix if it doesn't start with a featureFlag prefix * serializeFeatureFlagParam for a feature flag with key="abcd" - test * put the typeof check before * delay from recorder * changelog
1 parent 36c2775 commit 18d78f2

File tree

4 files changed

+52
-35
lines changed

4 files changed

+52
-35
lines changed

sdk/appconfiguration/app-configuration/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 1.2.0-beta.2 (Unreleased)
4+
5+
- With [#15136](https://github.com/Azure/azure-sdk-for-js/pull/15136), if the key of a feature flag(setting with `contentType="application/vnd.microsoft.appconfig.ff+json;charset=utf-8"`) doesn't start with `".appconfig.featureflag/"` (featureFlagPrefix), SDK adds the prefix before sending the request.
6+
37
## 1.2.0-beta.1 (2021-04-06)
48

59
### New Features

sdk/appconfiguration/app-configuration/src/featureFlag.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ export function deserializeFeatureFlag(setting: ConfigurationSetting): FeatureFl
242242
* @internal
243243
*/
244244
export function serializeFeatureFlagParam(setting: FeatureFlagParam): ConfigurationSettingParam {
245+
if (typeof setting.key === "string" && !setting.key.startsWith(featureFlagPrefix)) {
246+
setting.key = featureFlagPrefix + setting.key;
247+
}
245248
const value: JsonFeatureFlag & { id: string } = {
246249
id: setting.key.replace(featureFlagPrefix, ""),
247250
description: setting.description,

sdk/appconfiguration/app-configuration/test/public/featureFlag.spec.ts

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,38 @@ import {
1616
} from "../../src";
1717
import { Recorder } from "@azure/test-utils-recorder";
1818
import { Context } from "mocha";
19+
import { serializeFeatureFlagParam } from "../../src/featureFlag";
1920

2021
describe("AppConfigurationClient - FeatureFlag", () => {
21-
let client: AppConfigurationClient;
22-
let recorder: Recorder;
22+
describe("FeatureFlag configuration setting", () => {
23+
let client: AppConfigurationClient;
24+
let recorder: Recorder;
2325

24-
beforeEach(function(this: Context) {
25-
recorder = startRecorder(this);
26-
client = createAppConfigurationClientForTests() || this.skip();
27-
});
26+
beforeEach(async function(this: Context) {
27+
recorder = startRecorder(this);
28+
client = createAppConfigurationClientForTests() || this.skip();
29+
baseSetting = {
30+
conditions: {
31+
clientFilters
32+
},
33+
enabled: false,
34+
isReadOnly: false,
35+
key: `${featureFlagPrefix + recorder.getUniqueName("name-1")}`,
36+
contentType: featureFlagContentType,
37+
description: "I'm a description",
38+
label: "label-1"
39+
};
40+
addResponse = await client.addConfigurationSetting(baseSetting);
41+
});
2842

29-
afterEach(async function(this: Context) {
30-
await recorder.stop();
31-
});
43+
afterEach(async function(this: Context) {
44+
await client.deleteConfigurationSetting({
45+
key: baseSetting.key,
46+
label: baseSetting.label
47+
});
48+
await recorder.stop();
49+
});
3250

33-
describe("FeatureFlag configuration setting", () => {
3451
const clientFilters: (
3552
| Record<string, unknown>
3653
| FeatureFlagTargetingClientFilter
@@ -64,28 +81,6 @@ describe("AppConfigurationClient - FeatureFlag", () => {
6481
let baseSetting: FeatureFlag;
6582
let addResponse: AddConfigurationSettingResponse;
6683

67-
beforeEach(async () => {
68-
baseSetting = {
69-
conditions: {
70-
clientFilters
71-
},
72-
enabled: false,
73-
isReadOnly: false,
74-
key: `${featureFlagPrefix + recorder.getUniqueName("name-1")}`,
75-
contentType: featureFlagContentType,
76-
description: "I'm a description",
77-
label: "label-1"
78-
};
79-
addResponse = await client.addConfigurationSetting(baseSetting);
80-
});
81-
82-
afterEach(async () => {
83-
await client.deleteConfigurationSetting({
84-
key: baseSetting.key,
85-
label: baseSetting.label
86-
});
87-
});
88-
8984
function assertFeatureFlagProps(
9085
actual: Omit<AddConfigurationSettingResponse, "_response">,
9186
expected: FeatureFlag
@@ -192,4 +187,21 @@ describe("AppConfigurationClient - FeatureFlag", () => {
192187
await client.deleteConfigurationSetting({ key: secondSetting.key });
193188
});
194189
});
190+
191+
describe("FeatureFlag utils", () => {
192+
[featureFlagPrefix + "abcd", "abcd"].forEach((key) => {
193+
it(`serializeFeatureFlagParam for a feature flag with key=${key}`, () => {
194+
assert.equal(
195+
serializeFeatureFlagParam({
196+
key,
197+
value: `xyz`,
198+
conditions: { clientFilters: [] },
199+
enabled: false
200+
}).key,
201+
featureFlagPrefix + "abcd",
202+
"Unexpected key in the setting"
203+
);
204+
});
205+
});
206+
});
195207
});

sdk/appconfiguration/app-configuration/test/public/index.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import {
1212
startRecorder
1313
} from "./utils/testHelpers";
1414
import { AppConfigurationClient, ConfigurationSetting, ConfigurationSettingParam } from "../../src";
15-
import { delay } from "@azure/core-http";
16-
import { Recorder } from "@azure/test-utils-recorder";
15+
import { Recorder, delay } from "@azure/test-utils-recorder";
1716
import { Context } from "mocha";
1817

1918
describe("AppConfigurationClient", () => {
@@ -421,7 +420,6 @@ describe("AppConfigurationClient", () => {
421420
});
422421

423422
await delay(1000);
424-
425423
await client.setConfigurationSetting({
426424
key,
427425
value: "value2"

0 commit comments

Comments
 (0)