Skip to content

Commit 7ae47a3

Browse files
committed
update changelog and fix lint
1 parent 4201e40 commit 7ae47a3

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

packages/remote-feature-flag-controller/CHANGELOG.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Add override functionality to remote feature flags ([#7271](https://github.com/MetaMask/core/pull/7271))
1313
- `setFlagOverride(flagName, value)` - Set a local override for a specific feature flag
14-
- `getFlagOverride(flagName)` - Get the current override value for a specific feature flag
1514
- `clearFlagOverride(flagName)` - Clear the local override for a specific feature flag
1615
- `clearAllOverrides()` - Clear all local feature flag overrides
17-
- `getFlag(flagName)` - Get the effective value of a feature flag (override takes precedence over remote)
18-
- `getAllFlags()` - Get all effective feature flags, combining remote flags with local overrides
19-
- Add A/B test visibility functionality ([#7271](https://github.com/MetaMask/core/pull/7271))
20-
- `getAvailableABTestGroups(flagName)` - Get available A/B test groups for a specific feature flag
21-
- `getAllABTestFlags()` - Get all feature flags that have A/B test groups available
2216
- Add new controller state properties ([#7271](https://github.com/MetaMask/core/pull/7271))
2317
- `localOverrides` - Local overrides for feature flags that take precedence over remote flags
2418
- `rawProcessedRemoteFeatureFlags` - Raw flag value for arrays that were processed from arrays to single value

packages/remote-feature-flag-controller/src/remote-feature-flag-controller.test.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,9 @@ describe('RemoteFeatureFlagController', () => {
783783
controller.setFlagOverride('testFlagForThreshold', 'overriddenValue');
784784

785785
// Access flag value with override taking precedence
786-
const flagValue = controller.state.localOverrides['testFlagForThreshold'] ?? controller.state.remoteFeatureFlags['testFlagForThreshold'];
786+
const flagValue =
787+
controller.state.localOverrides.testFlagForThreshold ??
788+
controller.state.remoteFeatureFlags.testFlagForThreshold;
787789
expect(flagValue).toBe('overriddenValue');
788790
});
789791
});
@@ -799,9 +801,8 @@ describe('RemoteFeatureFlagController', () => {
799801

800802
await controller.updateRemoteFeatureFlags();
801803

802-
const groups = controller.state.rawProcessedRemoteFeatureFlags[
803-
'testFlagForThreshold'
804-
];
804+
const groups =
805+
controller.state.rawProcessedRemoteFeatureFlags.testFlagForThreshold;
805806

806807
expect(groups).toStrictEqual([
807808
{
@@ -831,15 +832,15 @@ describe('RemoteFeatureFlagController', () => {
831832
await controller.updateRemoteFeatureFlags();
832833

833834
expect(
834-
controller.state.rawProcessedRemoteFeatureFlags['simpleFlag']
835+
controller.state.rawProcessedRemoteFeatureFlags.simpleFlag,
835836
).toBeUndefined();
836837
});
837838

838839
it('returns undefined for non-existent flags', () => {
839840
const controller = createController();
840841

841842
expect(
842-
controller.state.rawProcessedRemoteFeatureFlags['nonExistentFlag']
843+
controller.state.rawProcessedRemoteFeatureFlags.nonExistentFlag,
843844
).toBeUndefined();
844845
});
845846
});
@@ -886,13 +887,17 @@ describe('RemoteFeatureFlagController', () => {
886887

887888
await controller.updateRemoteFeatureFlags();
888889

889-
expect(controller.state.rawProcessedRemoteFeatureFlags).toStrictEqual({});
890+
expect(controller.state.rawProcessedRemoteFeatureFlags).toStrictEqual(
891+
{},
892+
);
890893
});
891894

892895
it('returns empty object when no flags exist', () => {
893896
const controller = createController();
894897

895-
expect(controller.state.rawProcessedRemoteFeatureFlags).toStrictEqual({});
898+
expect(controller.state.rawProcessedRemoteFeatureFlags).toStrictEqual(
899+
{},
900+
);
896901
});
897902
});
898903

@@ -911,15 +916,17 @@ describe('RemoteFeatureFlagController', () => {
911916
await controller.updateRemoteFeatureFlags();
912917

913918
// Only A/B test flags should be stored in rawProcessedRemoteFeatureFlags
914-
expect(Object.keys(controller.state.rawProcessedRemoteFeatureFlags)).toStrictEqual([
915-
'testFlagForThreshold',
916-
]);
919+
expect(
920+
Object.keys(controller.state.rawProcessedRemoteFeatureFlags),
921+
).toStrictEqual(['testFlagForThreshold']);
917922
expect(
918923
controller.state.rawProcessedRemoteFeatureFlags.testFlagForThreshold,
919924
).toStrictEqual(MOCK_FLAGS_WITH_THRESHOLD.testFlagForThreshold);
920925

921926
// Simple flags should not be in rawProcessedRemoteFeatureFlags
922-
expect(controller.state.rawProcessedRemoteFeatureFlags.simpleFlag).toBeUndefined();
927+
expect(
928+
controller.state.rawProcessedRemoteFeatureFlags.simpleFlag,
929+
).toBeUndefined();
923930
expect(
924931
controller.state.rawProcessedRemoteFeatureFlags.anotherSimpleFlag,
925932
).toBeUndefined();
@@ -939,9 +946,8 @@ describe('RemoteFeatureFlagController', () => {
939946
await controller.updateRemoteFeatureFlags();
940947

941948
// Get available groups
942-
const groups = controller.state.rawProcessedRemoteFeatureFlags[
943-
'testFlagForThreshold'
944-
];
949+
const groups =
950+
controller.state.rawProcessedRemoteFeatureFlags.testFlagForThreshold;
945951
expect(groups).toBeDefined();
946952
// Ensure groups is not undefined before accessing array elements
947953
if (!groups) {
@@ -950,12 +956,18 @@ describe('RemoteFeatureFlagController', () => {
950956
expect(groups).toHaveLength(3); // Expecting 3 groups based on MOCK_FLAGS_WITH_THRESHOLD
951957

952958
// Override with a specific group value
953-
const firstGroup = Array.isArray(groups) && groups.length > 0 ? groups[0] : null;
954-
const groupValue = firstGroup && typeof firstGroup === 'object' && 'value' in firstGroup ? firstGroup.value : 'valueA';
959+
const firstGroup =
960+
Array.isArray(groups) && groups.length > 0 ? groups[0] : null;
961+
const groupValue =
962+
firstGroup && typeof firstGroup === 'object' && 'value' in firstGroup
963+
? firstGroup.value
964+
: 'valueA';
955965
controller.setFlagOverride('testFlagForThreshold', groupValue); // groupA value
956966

957967
// Access flag value with override taking precedence
958-
const flagValue = controller.state.localOverrides['testFlagForThreshold'] ?? controller.state.remoteFeatureFlags['testFlagForThreshold'];
968+
const flagValue =
969+
controller.state.localOverrides.testFlagForThreshold ??
970+
controller.state.remoteFeatureFlags.testFlagForThreshold;
959971
expect(flagValue).toBe('valueA');
960972
});
961973

@@ -969,9 +981,8 @@ describe('RemoteFeatureFlagController', () => {
969981
controller.setFlagOverride('testFlagForThreshold', 'overrideValue');
970982

971983
// A/B test raw flags should still be available
972-
const groups = controller.state.rawProcessedRemoteFeatureFlags[
973-
'testFlagForThreshold'
974-
];
984+
const groups =
985+
controller.state.rawProcessedRemoteFeatureFlags.testFlagForThreshold;
975986
expect(groups).toHaveLength(3);
976987
expect(
977988
controller.state.rawProcessedRemoteFeatureFlags.testFlagForThreshold,

packages/remote-feature-flag-controller/src/remote-feature-flag-controller.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
FeatureFlags,
1313
ServiceResponse,
1414
FeatureFlagScopeValue,
15-
FeatureFlagScope,
1615
} from './remote-feature-flag-controller-types';
1716
import {
1817
generateDeterministicRandomNumber,
@@ -97,7 +96,7 @@ export type RemoteFeatureFlagControllerActions =
9796
| RemoteFeatureFlagControllerUpdateRemoteFeatureFlagsAction
9897
| RemoteFeatureFlagControllerSetFlagOverrideAction
9998
| RemoteFeatureFlagControllerClearFlagOverrideAction
100-
| RemoteFeatureFlagControllerClearAllOverridesAction
99+
| RemoteFeatureFlagControllerClearAllOverridesAction;
101100

102101
export type RemoteFeatureFlagControllerStateChangeEvent =
103102
ControllerStateChangeEvent<
@@ -274,9 +273,10 @@ export class RemoteFeatureFlagController extends BaseController<
274273
return getVersionData(flagValue, this.#clientVersion);
275274
}
276275

277-
async #processRemoteFeatureFlags(
278-
remoteFeatureFlags: FeatureFlags,
279-
): Promise<{ processedFlags: FeatureFlags; rawProcessedRemoteFeatureFlags: FeatureFlags }> {
276+
async #processRemoteFeatureFlags(remoteFeatureFlags: FeatureFlags): Promise<{
277+
processedFlags: FeatureFlags;
278+
rawProcessedRemoteFeatureFlags: FeatureFlags;
279+
}> {
280280
const processedRemoteFeatureFlags: FeatureFlags = {};
281281
const rawProcessedRemoteFeatureFlags: FeatureFlags = {};
282282
const metaMetricsId = this.#getMetaMetricsId();
@@ -295,7 +295,8 @@ export class RemoteFeatureFlagController extends BaseController<
295295

296296
if (Array.isArray(processedValue) && thresholdValue) {
297297
// Store the raw A/B test array for later use
298-
rawProcessedRemoteFeatureFlags[remoteFeatureFlagName] = remoteFeatureFlagValue;
298+
rawProcessedRemoteFeatureFlags[remoteFeatureFlagName] =
299+
remoteFeatureFlagValue;
299300

300301
const selectedGroup = processedValue.find(
301302
(featureFlag): featureFlag is FeatureFlagScopeValue => {
@@ -316,7 +317,10 @@ export class RemoteFeatureFlagController extends BaseController<
316317

317318
processedRemoteFeatureFlags[remoteFeatureFlagName] = processedValue;
318319
}
319-
return { processedFlags: processedRemoteFeatureFlags, rawProcessedRemoteFeatureFlags };
320+
return {
321+
processedFlags: processedRemoteFeatureFlags,
322+
rawProcessedRemoteFeatureFlags,
323+
};
320324
}
321325

322326
/**
@@ -347,12 +351,13 @@ export class RemoteFeatureFlagController extends BaseController<
347351
...this.state.localOverrides,
348352
[flagName]: value,
349353
},
350-
rawProcessedRemoteFeatureFlags: this.state.rawProcessedRemoteFeatureFlags,
354+
rawProcessedRemoteFeatureFlags:
355+
this.state.rawProcessedRemoteFeatureFlags,
351356
cacheTimestamp: this.state.cacheTimestamp,
352357
};
353358
});
354359
}
355-
360+
356361
/**
357362
* Clears the local override for a specific feature flag.
358363
*
@@ -365,7 +370,8 @@ export class RemoteFeatureFlagController extends BaseController<
365370
return {
366371
remoteFeatureFlags: this.state.remoteFeatureFlags,
367372
localOverrides: newOverrides,
368-
rawProcessedRemoteFeatureFlags: this.state.rawProcessedRemoteFeatureFlags,
373+
rawProcessedRemoteFeatureFlags:
374+
this.state.rawProcessedRemoteFeatureFlags,
369375
cacheTimestamp: this.state.cacheTimestamp,
370376
};
371377
});
@@ -379,7 +385,8 @@ export class RemoteFeatureFlagController extends BaseController<
379385
return {
380386
remoteFeatureFlags: this.state.remoteFeatureFlags,
381387
localOverrides: {},
382-
rawProcessedRemoteFeatureFlags: this.state.rawProcessedRemoteFeatureFlags,
388+
rawProcessedRemoteFeatureFlags:
389+
this.state.rawProcessedRemoteFeatureFlags,
383390
cacheTimestamp: this.state.cacheTimestamp,
384391
};
385392
});

0 commit comments

Comments
 (0)