Skip to content

Commit

Permalink
fix(3742): change getMetaMetricsId to only sync func type
Browse files Browse the repository at this point in the history
  • Loading branch information
DDDDDanica committed Jan 6, 2025
1 parent 035745f commit 15428da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function createController(
state: Partial<RemoteFeatureFlagControllerState>;
clientConfigApiService: AbstractClientConfigApiService;
disabled: boolean;
getMetaMetricsId: () => Promise<string> | string;
getMetaMetricsId: () => string;
}> = {},
) {
return new RemoteFeatureFlagController({
Expand All @@ -69,7 +69,7 @@ function createController(
options.clientConfigApiService ?? buildClientConfigApiService(),
disabled: options.disabled,
getMetaMetricsId:

Check failure on line 71 in packages/remote-feature-flag-controller/src/remote-feature-flag-controller.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

Delete `⏎···`
options.getMetaMetricsId ?? (() => Promise.resolve(MOCK_METRICS_ID)),
options.getMetaMetricsId ?? (() => MOCK_METRICS_ID),
});
}

Expand Down Expand Up @@ -273,7 +273,7 @@ describe('RemoteFeatureFlagController', () => {
});
const controller = createController({
clientConfigApiService,
getMetaMetricsId: () => Promise.resolve(MOCK_METRICS_ID),
getMetaMetricsId: () => MOCK_METRICS_ID,
});
await controller.updateRemoteFeatureFlags();

Expand All @@ -291,33 +291,14 @@ describe('RemoteFeatureFlagController', () => {
});
const controller = createController({
clientConfigApiService,
getMetaMetricsId: () => Promise.resolve(MOCK_METRICS_ID),
getMetaMetricsId: () => MOCK_METRICS_ID,
});
await controller.updateRemoteFeatureFlags();

const { testFlagForThreshold, ...nonThresholdFlags } =
controller.state.remoteFeatureFlags;
expect(nonThresholdFlags).toStrictEqual(MOCK_FLAGS);
});

it('handles synchronous metaMetricsId', async () => {
const clientConfigApiService = buildClientConfigApiService({
remoteFeatureFlags: MOCK_FLAGS_WITH_THRESHOLD,
});
const controller = createController({
clientConfigApiService,
getMetaMetricsId: () => MOCK_METRICS_ID,
});

await controller.updateRemoteFeatureFlags();

expect(
controller.state.remoteFeatureFlags.testFlagForThreshold,
).toStrictEqual({
name: 'groupC',
value: 'valueC',
});
});
});

describe('enable and disable', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class RemoteFeatureFlagController extends BaseController<

#inProgressFlagUpdate?: Promise<ServiceResponse>;

#getMetaMetricsId: () => string | Promise<string>;
#getMetaMetricsId: () => string;

/**
* Constructs a new RemoteFeatureFlagController instance.
Expand All @@ -126,7 +126,7 @@ export class RemoteFeatureFlagController extends BaseController<
messenger: RemoteFeatureFlagControllerMessenger;
state?: Partial<RemoteFeatureFlagControllerState>;
clientConfigApiService: AbstractClientConfigApiService;
getMetaMetricsId: () => string | Promise<string>;
getMetaMetricsId: () => string;
fetchInterval?: number;
disabled?: boolean;
}) {
Expand Down Expand Up @@ -208,11 +208,7 @@ export class RemoteFeatureFlagController extends BaseController<
remoteFeatureFlags: FeatureFlags,
): Promise<FeatureFlags> {
const processedRemoteFeatureFlags: FeatureFlags = {};
const metaMetricsIdResult = this.#getMetaMetricsId();
const metaMetricsId =
metaMetricsIdResult instanceof Promise
? await metaMetricsIdResult
: metaMetricsIdResult;
const metaMetricsId = this.#getMetaMetricsId();

const clientType = this.#clientConfigApiService.getClient();
const thresholdValue = generateDeterministicRandomNumber(
Expand Down

0 comments on commit 15428da

Please sign in to comment.