Skip to content

Commit

Permalink
[App Config] Add the prefix if not present for feature flags (Azure#1…
Browse files Browse the repository at this point in the history
…5136)

* 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
  • Loading branch information
HarshaNalluru committed May 5, 2021
1 parent 36c2775 commit 18d78f2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 35 deletions.
4 changes: 4 additions & 0 deletions sdk/appconfiguration/app-configuration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History

## 1.2.0-beta.2 (Unreleased)

- 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.

## 1.2.0-beta.1 (2021-04-06)

### New Features
Expand Down
3 changes: 3 additions & 0 deletions sdk/appconfiguration/app-configuration/src/featureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ export function deserializeFeatureFlag(setting: ConfigurationSetting): FeatureFl
* @internal
*/
export function serializeFeatureFlagParam(setting: FeatureFlagParam): ConfigurationSettingParam {
if (typeof setting.key === "string" && !setting.key.startsWith(featureFlagPrefix)) {
setting.key = featureFlagPrefix + setting.key;
}
const value: JsonFeatureFlag & { id: string } = {
id: setting.key.replace(featureFlagPrefix, ""),
description: setting.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,38 @@ import {
} from "../../src";
import { Recorder } from "@azure/test-utils-recorder";
import { Context } from "mocha";
import { serializeFeatureFlagParam } from "../../src/featureFlag";

describe("AppConfigurationClient - FeatureFlag", () => {
let client: AppConfigurationClient;
let recorder: Recorder;
describe("FeatureFlag configuration setting", () => {
let client: AppConfigurationClient;
let recorder: Recorder;

beforeEach(function(this: Context) {
recorder = startRecorder(this);
client = createAppConfigurationClientForTests() || this.skip();
});
beforeEach(async function(this: Context) {
recorder = startRecorder(this);
client = createAppConfigurationClientForTests() || this.skip();
baseSetting = {
conditions: {
clientFilters
},
enabled: false,
isReadOnly: false,
key: `${featureFlagPrefix + recorder.getUniqueName("name-1")}`,
contentType: featureFlagContentType,
description: "I'm a description",
label: "label-1"
};
addResponse = await client.addConfigurationSetting(baseSetting);
});

afterEach(async function(this: Context) {
await recorder.stop();
});
afterEach(async function(this: Context) {
await client.deleteConfigurationSetting({
key: baseSetting.key,
label: baseSetting.label
});
await recorder.stop();
});

describe("FeatureFlag configuration setting", () => {
const clientFilters: (
| Record<string, unknown>
| FeatureFlagTargetingClientFilter
Expand Down Expand Up @@ -64,28 +81,6 @@ describe("AppConfigurationClient - FeatureFlag", () => {
let baseSetting: FeatureFlag;
let addResponse: AddConfigurationSettingResponse;

beforeEach(async () => {
baseSetting = {
conditions: {
clientFilters
},
enabled: false,
isReadOnly: false,
key: `${featureFlagPrefix + recorder.getUniqueName("name-1")}`,
contentType: featureFlagContentType,
description: "I'm a description",
label: "label-1"
};
addResponse = await client.addConfigurationSetting(baseSetting);
});

afterEach(async () => {
await client.deleteConfigurationSetting({
key: baseSetting.key,
label: baseSetting.label
});
});

function assertFeatureFlagProps(
actual: Omit<AddConfigurationSettingResponse, "_response">,
expected: FeatureFlag
Expand Down Expand Up @@ -192,4 +187,21 @@ describe("AppConfigurationClient - FeatureFlag", () => {
await client.deleteConfigurationSetting({ key: secondSetting.key });
});
});

describe("FeatureFlag utils", () => {
[featureFlagPrefix + "abcd", "abcd"].forEach((key) => {
it(`serializeFeatureFlagParam for a feature flag with key=${key}`, () => {
assert.equal(
serializeFeatureFlagParam({
key,
value: `xyz`,
conditions: { clientFilters: [] },
enabled: false
}).key,
featureFlagPrefix + "abcd",
"Unexpected key in the setting"
);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
startRecorder
} from "./utils/testHelpers";
import { AppConfigurationClient, ConfigurationSetting, ConfigurationSettingParam } from "../../src";
import { delay } from "@azure/core-http";
import { Recorder } from "@azure/test-utils-recorder";
import { Recorder, delay } from "@azure/test-utils-recorder";
import { Context } from "mocha";

describe("AppConfigurationClient", () => {
Expand Down Expand Up @@ -421,7 +420,6 @@ describe("AppConfigurationClient", () => {
});

await delay(1000);

await client.setConfigurationSetting({
key,
value: "value2"
Expand Down

0 comments on commit 18d78f2

Please sign in to comment.