Skip to content
17 changes: 11 additions & 6 deletions tests/api-mocking/helpers/remoteFeatureFlagsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const createRemoteFeatureFlagsMock = (
export const setupRemoteFeatureFlagsMock = async (
mockServer: Mockttp,
flagOverrides: Record<string, unknown> = {},
priority?: number,
): Promise<void> => {
const environments = ['dev', 'test', 'prod'] as const;
const distributions = ['main', 'flask'] as const;
Expand All @@ -140,12 +141,16 @@ export const setupRemoteFeatureFlagsMock = async (
const { urlEndpoint, response, responseCode } =
createRemoteFeatureFlagsMock(flagOverrides, distribution, environment);

return setupMockRequest(mockServer, {
requestMethod: 'GET',
url: urlEndpoint,
response,
responseCode,
});
return setupMockRequest(
mockServer,
{
requestMethod: 'GET',
url: urlEndpoint,
response,
responseCode,
},
priority,
);
}),
);

Expand Down
14 changes: 11 additions & 3 deletions tests/framework/fixtures/FixtureHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,17 @@ export const createMockAPIServer = async (
// Additional Global Mocks
await mockNotificationServices(mockServer);

// Feature Flags
// testSpecificMock can override this if needed
await setupRemoteFeatureFlagsMock(mockServer);
// Feature Flags — registered at priority 2 so testSpecificMock rules at
// priority 999 always win for every subsequent fetch.
// RemoteFeatureFlagController polls every 1 second in DEV mode; without this
// priority separation the default mock would override test-specific flag
// overrides on the second request, breaking flag-dependent flows mid-test.
//
// Priority 2 (not 1) is intentional: the MockServerE2E catch-all /proxy handler
// uses mockttp's DEFAULT priority (1). Priority 2 ensures this default feature
// flags mock wins over the catch-all for tests that have no testSpecificMock,
// preventing unmocked live requests to client-config.api.cx.metamask.io.
await setupRemoteFeatureFlagsMock(mockServer, undefined, 2);

const endpoints = await mockServer.getMockedEndpoints();
logger.debug(`Mocked endpoints: ${endpoints.length}`);
Expand Down
Loading