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
25 changes: 25 additions & 0 deletions packages/app/lib/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,28 @@ const mapOfDeprecationReplacements = {
nanoseconds: NO_REPLACEMENT,
},
},
remoteConfig: {
default: {
activate: 'activate()',
ensureInitialized: 'ensureInitialized()',
fetchAndActivate: 'fetchAndActivate()',
getAll: 'getAll()',
getBoolean: 'getBoolean()',
getNumber: 'getNumber()',
getString: 'getString()',
getValue: 'getValue()',
reset: 'reset()',
setConfigSettings: 'setConfigSettings()',
fetch: 'fetch()',
setDefaults: 'setDefaults()',
setDefaultsFromResource: 'setDefaultsFromResource()',
onConfigUpdated: 'onConfigUpdated()',
},
statics: {
LastFetchStatus: 'LastFetchStatus',
ValueSource: 'ValueSource',
},
},
storage: {
default: {
useEmulator: 'connectStorageEmulator()',
Expand Down Expand Up @@ -493,6 +515,9 @@ export function createDeprecationProxy(instance) {
) {
deprecationConsoleWarning('firestore', prop, 'statics', false);
}
if (prop === 'LastFetchStatus' || prop === 'ValueSource') {
deprecationConsoleWarning('remoteConfig', prop, 'statics', false);
}
if (prop === 'CustomProvider') {
deprecationConsoleWarning('appCheck', prop, 'statics', false);
}
Expand Down
187 changes: 186 additions & 1 deletion packages/remote-config/__tests__/remote-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
import { afterAll, beforeAll, describe, expect, it, beforeEach, jest } from '@jest/globals';

import {
firebase,
Expand Down Expand Up @@ -44,6 +44,14 @@ import {
ValueSource,
} from '../lib';

import {
createCheckV9Deprecation,
CheckV9DeprecationFunction,
} from '../../app/lib/common/unitTestUtils';

// @ts-ignore test
import FirebaseModule from '../../app/lib/internal/FirebaseModule';

describe('remoteConfig()', function () {
describe('namespace', function () {
beforeAll(async function () {
Expand Down Expand Up @@ -246,5 +254,182 @@ describe('remoteConfig()', function () {
expect(ValueSource.REMOTE).toBeDefined();
expect(ValueSource.STATIC).toBeDefined();
});

describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () {
let remoteConfigV9Deprecation: CheckV9DeprecationFunction;
let staticsV9Deprecation: CheckV9DeprecationFunction;

beforeEach(function () {
remoteConfigV9Deprecation = createCheckV9Deprecation(['remoteConfig']);

staticsV9Deprecation = createCheckV9Deprecation(['remoteConfig', 'statics']);

// @ts-ignore test
jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => {
return new Proxy(
{},
{
get: () =>
jest.fn().mockResolvedValue({
result: true,
constants: {
lastFetchTime: Date.now(),
lastFetchStatus: 'success',
fetchTimeout: 60,
minimumFetchInterval: 12,
values: {},
},
} as never),
},
);
});
});

describe('remoteConfig functions', function () {
it('activate()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => activate(remoteConfig),
() => remoteConfig.activate(),
'activate',
);
});

it('ensureInitialized()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => ensureInitialized(remoteConfig),
() => remoteConfig.ensureInitialized(),
'ensureInitialized',
);
});

it('fetchAndActivate()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => fetchAndActivate(remoteConfig),
() => remoteConfig.fetchAndActivate(),
'fetchAndActivate',
);
});

it('getAll()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => getAll(remoteConfig),
() => remoteConfig.getAll(),
'getAll',
);
});

it('getBoolean()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => getBoolean(remoteConfig, 'foo'),
() => remoteConfig.getBoolean('foo'),
'getBoolean',
);
});

it('getNumber()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => getNumber(remoteConfig, 'foo'),
() => remoteConfig.getNumber('foo'),
'getNumber',
);
});

it('getString()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => getString(remoteConfig, 'foo'),
() => remoteConfig.getString('foo'),
'getString',
);
});

it('getValue()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => getValue(remoteConfig, 'foo'),
() => remoteConfig.getValue('foo'),
'getValue',
);
});

it('reset()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => reset(remoteConfig),
() => remoteConfig.reset(),
'reset',
);
});

it('setConfigSettings()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => setConfigSettings(remoteConfig, { minimumFetchIntervalMillis: 12 }),
() => remoteConfig.setConfigSettings({ minimumFetchIntervalMillis: 12 }),
'setConfigSettings',
);
});

it('fetch()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => fetch(remoteConfig, 12),
() => remoteConfig.fetch(12),
'fetch',
);
});

it('setDefaults()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => setDefaults(remoteConfig, { foo: 'bar' }),
() => remoteConfig.setDefaults({ foo: 'bar' }),
'setDefaults',
);
});

it('setDefaultsFromResource()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => setDefaultsFromResource(remoteConfig, 'foo'),
() => remoteConfig.setDefaultsFromResource('foo'),
'setDefaultsFromResource',
);
});

it('onConfigUpdated()', function () {
const remoteConfig = getRemoteConfig();
remoteConfigV9Deprecation(
() => onConfigUpdated(remoteConfig, () => {}),
() => remoteConfig.onConfigUpdated(() => {}),
'onConfigUpdated',
);
});
});

describe('statics', function () {
it('LastFetchStatus', function () {
staticsV9Deprecation(
() => LastFetchStatus.FAILURE,
() => firebase.remoteConfig.LastFetchStatus.FAILURE,
'LastFetchStatus',
);
});

it('ValueSource', function () {
staticsV9Deprecation(
() => ValueSource.DEFAULT,
() => firebase.remoteConfig.ValueSource.DEFAULT,
'ValueSource',
);
});
});
});
});
});
4 changes: 2 additions & 2 deletions packages/remote-config/e2e/config.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ describe('remoteConfig()', function () {

describe('fetch()', function () {
it('with expiration provided', async function () {
const { getRemoteConfig, ensureInitialized, fetch } = remoteConfigModular;
const { getRemoteConfig, ensureInitialized, fetch, LastFetchStatus } = remoteConfigModular;
const date = Date.now() - 30000;
const remoteConfig = getRemoteConfig();
await ensureInitialized(remoteConfig);
Expand All @@ -390,7 +390,7 @@ describe('remoteConfig()', function () {
}

await fetch(remoteConfig, 0);
remoteConfig.lastFetchStatus.should.equal(firebase.remoteConfig.LastFetchStatus.SUCCESS);
remoteConfig.lastFetchStatus.should.equal(LastFetchStatus.SUCCESS);
should.equal(getRemoteConfig().fetchTimeMillis >= date, true);
});

Expand Down
Loading
Loading