Skip to content

Commit

Permalink
test(remote-config): ensure modular API are exported properly (#7940)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Jul 29, 2024
1 parent 63ccfae commit 5689f24
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 56 deletions.
111 changes: 110 additions & 1 deletion packages/remote-config/__tests__/remote-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,30 @@
*/
import { describe, expect, it } from '@jest/globals';

import { firebase } from '../lib';
import {
firebase,
getRemoteConfig,
activate,
ensureInitialized,
fetchAndActivate,
fetchConfig,
getAll,
getBoolean,
getNumber,
getString,
getValue,
setLogLevel,
isSupported,
fetchTimeMillis,
settings,
lastFetchStatus,
reset,
setConfigSettings,
fetch,
setDefaults,
setDefaultsFromResource,
onConfigUpdated,
} from '../lib';

describe('remoteConfig()', function () {
describe('namespace', function () {
Expand Down Expand Up @@ -108,4 +131,90 @@ describe('remoteConfig()', function () {
expect(config).toEqual({});
});
});

describe('modular', function () {
it('`getRemoteConfig` function is properly exposed to end user', function () {
expect(getRemoteConfig).toBeDefined();
});

it('`activate` function is properly exposed to end user', function () {
expect(activate).toBeDefined();
});

it('`ensureInitialized` function is properly exposed to end user', function () {
expect(ensureInitialized).toBeDefined();
});

it('`fetchAndActivate` function is properly exposed to end user', function () {
expect(fetchAndActivate).toBeDefined();
});

it('`fetchConfig` function is properly exposed to end user', function () {
expect(fetchConfig).toBeDefined();
});

it('`getAll` function is properly exposed to end user', function () {
expect(getAll).toBeDefined();
});

it('`getBoolean` function is properly exposed to end user', function () {
expect(getBoolean).toBeDefined();
});

it('`getNumber` function is properly exposed to end user', function () {
expect(getNumber).toBeDefined();
});

it('`getString` function is properly exposed to end user', function () {
expect(getString).toBeDefined();
});

it('`getValue` function is properly exposed to end user', function () {
expect(getValue).toBeDefined();
});

it('`setLogLevel` function is properly exposed to end user', function () {
expect(setLogLevel).toBeDefined();
});

it('`isSupported` function is properly exposed to end user', function () {
expect(isSupported).toBeDefined();
});

it('`fetchTimeMillis` function is properly exposed to end user', function () {
expect(fetchTimeMillis).toBeDefined();
});

it('`settings` function is properly exposed to end user', function () {
expect(settings).toBeDefined();
});

it('`lastFetchStatus` function is properly exposed to end user', function () {
expect(lastFetchStatus).toBeDefined();
});

it('`reset` function is properly exposed to end user', function () {
expect(reset).toBeDefined();
});

it('`setConfigSettings` function is properly exposed to end user', function () {
expect(setConfigSettings).toBeDefined();
});

it('`fetch` function is properly exposed to end user', function () {
expect(fetch).toBeDefined();
});

it('`setDefaults` function is properly exposed to end user', function () {
expect(setDefaults).toBeDefined();
});

it('`setDefaultsFromResource` function is properly exposed to end user', function () {
expect(setDefaultsFromResource).toBeDefined();
});

it('`onConfigUpdated` function is properly exposed to end user', function () {
expect(onConfigUpdated).toBeDefined();
});
});
});
2 changes: 2 additions & 0 deletions packages/remote-config/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ type OnConfigUpdatedListenerCallback = (

export default defaultExport;

export * from './modular';

/**
* Attach namespace to `firebase.` and `FirebaseApp.`.
*/
Expand Down
26 changes: 2 additions & 24 deletions packages/remote-config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,6 @@ import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/na
import fallBackModule from './web/RNFBConfigModule';
import version from './version';

export {
getRemoteConfig,
activate,
ensureInitialized,
fetchAndActivate,
fetchConfig,
getAll,
getBoolean,
getNumber,
getString,
getValue,
setLogLevel,
isSupported,
fetchTimeMillis,
settings,
lastFetchStatus,
reset,
setConfigSettings,
fetch,
setDefaults,
setDefaultsFromResource,
onConfigUpdated,
} from './modular/index';

const statics = {
LastFetchStatus: {
SUCCESS: 'success',
Expand Down Expand Up @@ -368,6 +344,8 @@ export default createModuleNamespace({
ModuleClass: FirebaseConfigModule,
});

export * from './modular';

// import config, { firebase } from '@react-native-firebase/remote-config';
// config().X(...);
// firebase.remoteConfig().X(...);
Expand Down
208 changes: 208 additions & 0 deletions packages/remote-config/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { FirebaseApp } from '@firebase/app-types';
import { FirebaseRemoteConfigTypes } from '..';

import RemoteConfig = FirebaseRemoteConfigTypes.Module;
import ConfigValues = FirebaseRemoteConfigTypes.ConfigValues;
import ConfigValue = FirebaseRemoteConfigTypes.ConfigValue;
import ConfigDefaults = FirebaseRemoteConfigTypes.ConfigDefaults;
import ConfigSettings = FirebaseRemoteConfigTypes.ConfigSettings;
import LastFetchStatusType = FirebaseRemoteConfigTypes.LastFetchStatusType;
import RemoteConfigLogLevel = FirebaseRemoteConfigTypes.RemoteConfigLogLevel;

/**
* Returns a RemoteConfig instance for the given app.
* @param app - FirebaseApp. Optional.
* @returns {RemoteConfig}
*/
export function getRemoteConfig(app?: FirebaseApp): RemoteConfig;

/**
* Returns a Boolean which resolves to true if the current call
* activated the fetched configs.
* @param remoteConfig - RemoteConfig instance
* @returns {Promise<boolean>}
*/
export function activate(remoteConfig: RemoteConfig): Promise<boolean>;

/**
* Ensures the last activated config are available to the getters.
* @param remoteConfig - RemoteConfig instance
* @returns {Promise<void>}
*/
export function ensureInitialized(remoteConfig: RemoteConfig): Promise<void>;

/**
* Performs a fetch and returns a Boolean which resolves to true
* if the current call activated the fetched configs.
* @param remoteConfig - RemoteConfig instance
* @returns {Promise<boolean>}
*/
export function fetchAndActivate(remoteConfig: RemoteConfig): Promise<boolean>;

/**
* Fetches and caches configuration from the Remote Config service.
* @param remoteConfig - RemoteConfig instance
* @returns {Promise<void>}
*/
export function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;

/**
* Gets all config.
* @param remoteConfig - RemoteConfig instance
* @returns {ConfigValues}
*/
export function getAll(remoteConfig: RemoteConfig): ConfigValues;

/**
* Gets the value for the given key as a boolean.
* @param remoteConfig - RemoteConfig instance
* @param key - key for boolean value
* @returns {boolean}
*/
export function getBoolean(remoteConfig: RemoteConfig, key: string): boolean;

/**
* Gets the value for the given key as a number.
* @param remoteConfig - RemoteConfig instance
* @param key - key for number value
* @returns {number}
*/
export function getNumber(remoteConfig: RemoteConfig, key: string): number;

/**
* Gets the value for the given key as a string.
* @param remoteConfig - RemoteConfig instance
* @param key - key for string value
* @returns {string}
*/
export function getString(remoteConfig: RemoteConfig, key: string): string;

/**
* Gets the value for the given key
* @param remoteConfig - RemoteConfig instance
* @param key - key for the given value
* @returns {ConfigValue}
*/
export function getValue(remoteConfig: RemoteConfig, key: string): ConfigValue;

/**
* Defines the log level to use.
* @param remoteConfig - RemoteConfig instance
* @param logLevel - The log level to set
* @returns {RemoteConfigLogLevel}
*/
export function setLogLevel(
remoteConfig: RemoteConfig,
logLevel: RemoteConfigLogLevel,
): RemoteConfigLogLevel;

/**
* Checks two different things.
* 1. Check if IndexedDB exists in the browser environment.
* 2. Check if the current browser context allows IndexedDB open() calls.
* @returns {Promise<boolean>}
*/
export function isSupported(): Promise<boolean>;

/**
* Indicates the default value in milliseconds to abandon a pending fetch
* request made to the Remote Config server. Defaults to 60000 (One minute).
* @param remoteConfig - RemoteConfig instance
* @returns {number}
*/
export function fetchTimeMillis(remoteConfig: RemoteConfig): number;

/**
* Returns a ConfigSettings object which provides the properties `minimumFetchIntervalMillis` & `fetchTimeMillis` if they have been set
* using setConfigSettings({ fetchTimeMillis: number, minimumFetchIntervalMillis: number }).
* @param remoteConfig - RemoteConfig instance
* @returns {ConfigSettings}
*/
export function settings(remoteConfig: RemoteConfig): ConfigSettings;

/**
* The status of the latest Remote RemoteConfig fetch action.
* @param remoteConfig - RemoteConfig instance
* @returns {LastFetchStatusType}
*/
export function lastFetchStatus(remoteConfig: RemoteConfig): LastFetchStatusType;

/**
* Deletes all activated, fetched and defaults configs and
* resets all Firebase Remote Config settings.
* Android only. iOS does not reset anything.
* @param remoteConfig - RemoteConfig instance
* @returns {Promise<void>}
*/
export function reset(remoteConfig: RemoteConfig): Promise<void>;

/**
* Set the Remote RemoteConfig settings, currently able to set
* `fetchTimeMillis` & `minimumFetchIntervalMillis`
* Android only. iOS does not reset anything.
* @param remoteConfig - RemoteConfig instance
* @param settings - ConfigSettings instance
* @returns {Promise<void>}
*/
export function setConfigSettings(
remoteConfig: RemoteConfig,
settings: ConfigSettings,
): Promise<void>;

/**
* Fetches parameter values for your app.
* @param remoteConfig - RemoteConfig instance
* @param expirationDurationSeconds - number
* @returns {Promise<void>}
*/
export function fetch(
remoteConfig: RemoteConfig,
expirationDurationSeconds?: number,
): Promise<void>;

/**
* Fetches parameter values for your app.
* @param remoteConfig - RemoteConfig instance
* @param defaults - ConfigDefaults
* @returns {Promise<void>}
*/
export function setDefaults(remoteConfig: RemoteConfig, defaults: ConfigDefaults): Promise<void>;

/**
* Fetches parameter values for your app.
* @param remoteConfig - RemoteConfig instance
* @param resourceName - string
* @returns {Promise<null>}
*/
export function setDefaultsFromResource(
remoteConfig: RemoteConfig,
resourceName: string,
): Promise<null>;

/**
* Registers a listener to changes in the configuration.
*
* @param remoteConfig - RemoteConfig instance
* @param callback - function called on config change
* @returns {function} unsubscribe listener
*/
export function onConfigUpdated(
remoteConfig: RemoteConfig,
callback: (config: ConfigValues) => void,
): () => void;
Loading

0 comments on commit 5689f24

Please sign in to comment.