|
14 | 14 | * limitations under the License.
|
15 | 15 | *
|
16 | 16 | */
|
17 |
| -import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'; |
| 17 | +import { afterAll, beforeAll, describe, expect, it, beforeEach, jest } from '@jest/globals'; |
18 | 18 |
|
19 | 19 | import {
|
20 | 20 | firebase,
|
@@ -44,6 +44,14 @@ import {
|
44 | 44 | ValueSource,
|
45 | 45 | } from '../lib';
|
46 | 46 |
|
| 47 | +import { |
| 48 | + createCheckV9Deprecation, |
| 49 | + CheckV9DeprecationFunction, |
| 50 | +} from '../../app/lib/common/unitTestUtils'; |
| 51 | + |
| 52 | +// @ts-ignore test |
| 53 | +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; |
| 54 | + |
47 | 55 | describe('remoteConfig()', function () {
|
48 | 56 | describe('namespace', function () {
|
49 | 57 | beforeAll(async function () {
|
@@ -246,5 +254,182 @@ describe('remoteConfig()', function () {
|
246 | 254 | expect(ValueSource.REMOTE).toBeDefined();
|
247 | 255 | expect(ValueSource.STATIC).toBeDefined();
|
248 | 256 | });
|
| 257 | + |
| 258 | + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { |
| 259 | + let remoteConfigV9Deprecation: CheckV9DeprecationFunction; |
| 260 | + let staticsV9Deprecation: CheckV9DeprecationFunction; |
| 261 | + |
| 262 | + beforeEach(function () { |
| 263 | + remoteConfigV9Deprecation = createCheckV9Deprecation(['remoteConfig']); |
| 264 | + |
| 265 | + staticsV9Deprecation = createCheckV9Deprecation(['remoteConfig', 'statics']); |
| 266 | + |
| 267 | + // @ts-ignore test |
| 268 | + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { |
| 269 | + return new Proxy( |
| 270 | + {}, |
| 271 | + { |
| 272 | + get: () => |
| 273 | + jest.fn().mockResolvedValue({ |
| 274 | + result: true, |
| 275 | + constants: { |
| 276 | + lastFetchTime: Date.now(), |
| 277 | + lastFetchStatus: 'success', |
| 278 | + fetchTimeout: 60, |
| 279 | + minimumFetchInterval: 12, |
| 280 | + values: {}, |
| 281 | + }, |
| 282 | + } as never), |
| 283 | + }, |
| 284 | + ); |
| 285 | + }); |
| 286 | + }); |
| 287 | + |
| 288 | + describe('remoteConfig functions', function () { |
| 289 | + it('activate()', function () { |
| 290 | + const remoteConfig = getRemoteConfig(); |
| 291 | + remoteConfigV9Deprecation( |
| 292 | + () => activate(remoteConfig), |
| 293 | + () => remoteConfig.activate(), |
| 294 | + 'activate', |
| 295 | + ); |
| 296 | + }); |
| 297 | + |
| 298 | + it('ensureInitialized()', function () { |
| 299 | + const remoteConfig = getRemoteConfig(); |
| 300 | + remoteConfigV9Deprecation( |
| 301 | + () => ensureInitialized(remoteConfig), |
| 302 | + () => remoteConfig.ensureInitialized(), |
| 303 | + 'ensureInitialized', |
| 304 | + ); |
| 305 | + }); |
| 306 | + |
| 307 | + it('fetchAndActivate()', function () { |
| 308 | + const remoteConfig = getRemoteConfig(); |
| 309 | + remoteConfigV9Deprecation( |
| 310 | + () => fetchAndActivate(remoteConfig), |
| 311 | + () => remoteConfig.fetchAndActivate(), |
| 312 | + 'fetchAndActivate', |
| 313 | + ); |
| 314 | + }); |
| 315 | + |
| 316 | + it('getAll()', function () { |
| 317 | + const remoteConfig = getRemoteConfig(); |
| 318 | + remoteConfigV9Deprecation( |
| 319 | + () => getAll(remoteConfig), |
| 320 | + () => remoteConfig.getAll(), |
| 321 | + 'getAll', |
| 322 | + ); |
| 323 | + }); |
| 324 | + |
| 325 | + it('getBoolean()', function () { |
| 326 | + const remoteConfig = getRemoteConfig(); |
| 327 | + remoteConfigV9Deprecation( |
| 328 | + () => getBoolean(remoteConfig, 'foo'), |
| 329 | + () => remoteConfig.getBoolean('foo'), |
| 330 | + 'getBoolean', |
| 331 | + ); |
| 332 | + }); |
| 333 | + |
| 334 | + it('getNumber()', function () { |
| 335 | + const remoteConfig = getRemoteConfig(); |
| 336 | + remoteConfigV9Deprecation( |
| 337 | + () => getNumber(remoteConfig, 'foo'), |
| 338 | + () => remoteConfig.getNumber('foo'), |
| 339 | + 'getNumber', |
| 340 | + ); |
| 341 | + }); |
| 342 | + |
| 343 | + it('getString()', function () { |
| 344 | + const remoteConfig = getRemoteConfig(); |
| 345 | + remoteConfigV9Deprecation( |
| 346 | + () => getString(remoteConfig, 'foo'), |
| 347 | + () => remoteConfig.getString('foo'), |
| 348 | + 'getString', |
| 349 | + ); |
| 350 | + }); |
| 351 | + |
| 352 | + it('getValue()', function () { |
| 353 | + const remoteConfig = getRemoteConfig(); |
| 354 | + remoteConfigV9Deprecation( |
| 355 | + () => getValue(remoteConfig, 'foo'), |
| 356 | + () => remoteConfig.getValue('foo'), |
| 357 | + 'getValue', |
| 358 | + ); |
| 359 | + }); |
| 360 | + |
| 361 | + it('reset()', function () { |
| 362 | + const remoteConfig = getRemoteConfig(); |
| 363 | + remoteConfigV9Deprecation( |
| 364 | + () => reset(remoteConfig), |
| 365 | + () => remoteConfig.reset(), |
| 366 | + 'reset', |
| 367 | + ); |
| 368 | + }); |
| 369 | + |
| 370 | + it('setConfigSettings()', function () { |
| 371 | + const remoteConfig = getRemoteConfig(); |
| 372 | + remoteConfigV9Deprecation( |
| 373 | + () => setConfigSettings(remoteConfig, { minimumFetchIntervalMillis: 12 }), |
| 374 | + () => remoteConfig.setConfigSettings({ minimumFetchIntervalMillis: 12 }), |
| 375 | + 'setConfigSettings', |
| 376 | + ); |
| 377 | + }); |
| 378 | + |
| 379 | + it('fetch()', function () { |
| 380 | + const remoteConfig = getRemoteConfig(); |
| 381 | + remoteConfigV9Deprecation( |
| 382 | + () => fetch(remoteConfig, 12), |
| 383 | + () => remoteConfig.fetch(12), |
| 384 | + 'fetch', |
| 385 | + ); |
| 386 | + }); |
| 387 | + |
| 388 | + it('setDefaults()', function () { |
| 389 | + const remoteConfig = getRemoteConfig(); |
| 390 | + remoteConfigV9Deprecation( |
| 391 | + () => setDefaults(remoteConfig, { foo: 'bar' }), |
| 392 | + () => remoteConfig.setDefaults({ foo: 'bar' }), |
| 393 | + 'setDefaults', |
| 394 | + ); |
| 395 | + }); |
| 396 | + |
| 397 | + it('setDefaultsFromResource()', function () { |
| 398 | + const remoteConfig = getRemoteConfig(); |
| 399 | + remoteConfigV9Deprecation( |
| 400 | + () => setDefaultsFromResource(remoteConfig, 'foo'), |
| 401 | + () => remoteConfig.setDefaultsFromResource('foo'), |
| 402 | + 'setDefaultsFromResource', |
| 403 | + ); |
| 404 | + }); |
| 405 | + |
| 406 | + it('onConfigUpdated()', function () { |
| 407 | + const remoteConfig = getRemoteConfig(); |
| 408 | + remoteConfigV9Deprecation( |
| 409 | + () => onConfigUpdated(remoteConfig, () => {}), |
| 410 | + () => remoteConfig.onConfigUpdated(() => {}), |
| 411 | + 'onConfigUpdated', |
| 412 | + ); |
| 413 | + }); |
| 414 | + }); |
| 415 | + |
| 416 | + describe('statics', function () { |
| 417 | + it('LastFetchStatus', function () { |
| 418 | + staticsV9Deprecation( |
| 419 | + () => LastFetchStatus.FAILURE, |
| 420 | + () => firebase.remoteConfig.LastFetchStatus.FAILURE, |
| 421 | + 'LastFetchStatus', |
| 422 | + ); |
| 423 | + }); |
| 424 | + |
| 425 | + it('ValueSource', function () { |
| 426 | + staticsV9Deprecation( |
| 427 | + () => ValueSource.DEFAULT, |
| 428 | + () => firebase.remoteConfig.ValueSource.DEFAULT, |
| 429 | + 'ValueSource', |
| 430 | + ); |
| 431 | + }); |
| 432 | + }); |
| 433 | + }); |
249 | 434 | });
|
250 | 435 | });
|
0 commit comments