Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/featureProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ConfigurationMapFeatureFlagProvider implements IFeatureFlagProvider
}
async getFeatureFlag(featureName: string): Promise<FeatureFlag | undefined> {
const featureConfig = this.#configuration.get<FeatureManagementConfiguration>(FEATURE_MANAGEMENT_KEY);
return featureConfig?.[FEATURE_FLAGS_KEY]?.find((feature) => feature.id === featureName);
return featureConfig?.[FEATURE_FLAGS_KEY]?.findLast((feature) => feature.id === featureName);
}

async getFeatureFlags(): Promise<FeatureFlag[]> {
Expand All @@ -49,7 +49,7 @@ export class ConfigurationObjectFeatureFlagProvider implements IFeatureFlagProvi

async getFeatureFlag(featureName: string): Promise<FeatureFlag | undefined> {
const featureFlags = this.#configuration[FEATURE_MANAGEMENT_KEY]?.[FEATURE_FLAGS_KEY];
return featureFlags?.find((feature: FeatureFlag) => feature.id === featureName);
return featureFlags?.findLast((feature: FeatureFlag) => feature.id === featureName);
}

async getFeatureFlags(): Promise<FeatureFlag[]> {
Expand Down
30 changes: 30 additions & 0 deletions test/featureManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,36 @@ describe("feature manager", () => {
]);
});

it("should let the last feature flag win", () => {
const jsonObject = {
"feature_management": {
"feature_flags": [
{ "id": "Alpha", "description": "", "enabled": false, "conditions": { "client_filters": [] } },
{ "id": "Alpha", "description": "", "enabled": true, "conditions": { "client_filters": [] } }
]
}
};

const provider1 = new ConfigurationObjectFeatureFlagProvider(jsonObject);
const featureManager1 = new FeatureManager(provider1);

const dataSource = new Map();
dataSource.set("feature_management", {
feature_flags: [
{ "id": "Alpha", "description": "", "enabled": false, "conditions": { "client_filters": [] } },
{ "id": "Alpha", "description": "", "enabled": true, "conditions": { "client_filters": [] } }
],
});

const provider2 = new ConfigurationMapFeatureFlagProvider(dataSource);
const featureManager2 = new FeatureManager(provider2);

return Promise.all([
expect(featureManager1.isEnabled("Alpha")).eventually.eq(true),
expect(featureManager2.isEnabled("Alpha")).eventually.eq(true)
]);
});

it("should evaluate features with conditions");
it("should override default filters with custom filters");
});
Loading