Skip to content

Commit c4f5f0d

Browse files
committed
test(functions): fix all functions e2e deprecation warnings
1 parent 0937c77 commit c4f5f0d

File tree

1 file changed

+57
-67
lines changed

1 file changed

+57
-67
lines changed

packages/functions/e2e/functions.e2e.js

Lines changed: 57 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ const SAMPLE_DATA = {
9090

9191
describe('functions() modular', function () {
9292
describe('firebase v8 compatibility', function () {
93+
beforeEach(async function beforeEachTest() {
94+
// @ts-ignore
95+
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true;
96+
});
97+
98+
afterEach(async function afterEachTest() {
99+
// @ts-ignore
100+
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false;
101+
});
102+
93103
describe('namespace', function () {
94104
it('accepts passing in an FirebaseApp instance as first arg', async function () {
95105
const appName = `functionsApp${FirebaseHelpers.id}2`;
@@ -407,27 +417,25 @@ describe('functions() modular', function () {
407417
describe('modular', function () {
408418
describe('getFunctions', function () {
409419
it('pass app as argument', function () {
420+
const { getApp } = modular;
410421
const { getFunctions } = functionsModular;
411-
412-
const functions = getFunctions(firebase.app());
413-
422+
const functions = getFunctions(getApp());
414423
functions.constructor.name.should.be.equal('FirebaseFunctionsModule');
415424
});
416425

417426
it('no app as argument', function () {
418427
const { getFunctions } = functionsModular;
419-
420428
const functions = getFunctions();
421-
422429
functions.constructor.name.should.be.equal('FirebaseFunctionsModule');
423430
});
424431
});
425432

426433
it('accepts passing in an FirebaseApp instance as first arg', async function () {
434+
const { initializeApp } = modular;
427435
const { getFunctions } = functionsModular;
428436
const appName = `functionsApp${FirebaseHelpers.id}3`;
429437
const platformAppConfig = FirebaseHelpers.app.config();
430-
const app = await firebase.initializeApp(platformAppConfig, appName);
438+
const app = await initializeApp(platformAppConfig, appName);
431439
const functions = getFunctions(app);
432440

433441
functions.app.should.equal(app);
@@ -439,18 +447,19 @@ describe('functions() modular', function () {
439447
});
440448

441449
it('accepts passing in a region string as first arg to an app', async function () {
450+
const { getApp } = modular;
442451
const { getFunctions } = functionsModular;
443452
const region = 'europe-west1';
444453

445-
const functionsForRegion = getFunctions(firebase.app(), region);
454+
const functionsForRegion = getFunctions(getApp(), region);
446455

447456
functionsForRegion._customUrlOrRegion.should.equal(region);
448-
functionsForRegion.app.should.equal(firebase.app());
449-
functionsForRegion.app.name.should.equal(firebase.app().name);
457+
functionsForRegion.app.should.equal(getApp());
458+
functionsForRegion.app.name.should.equal(getApp().name);
450459

451-
firebase.app().functions(region).app.should.equal(firebase.app());
460+
getApp().functions(region).app.should.equal(getApp());
452461

453-
firebase.app().functions(region)._customUrlOrRegion.should.equal(region);
462+
getApp().functions(region)._customUrlOrRegion.should.equal(region);
454463

455464
const functionRunner = functionsForRegion.httpsCallable('testFunctionCustomRegion');
456465

@@ -459,16 +468,17 @@ describe('functions() modular', function () {
459468
});
460469

461470
it('accepts passing in a custom url string as first arg to an app', async function () {
471+
const { getApp } = modular;
462472
const { getFunctions } = functionsModular;
463473
const customUrl = 'https://us-central1-react-native-firebase-testing.cloudfunctions.net';
464474

465-
const functionsForCustomUrl = getFunctions(firebase.app(), customUrl);
475+
const functionsForCustomUrl = getFunctions(getApp(), customUrl);
466476

467477
functionsForCustomUrl._customUrlOrRegion.should.equal(customUrl);
468-
functionsForCustomUrl.app.should.equal(firebase.app());
469-
functionsForCustomUrl.app.name.should.equal(firebase.app().name);
478+
functionsForCustomUrl.app.should.equal(getApp());
479+
functionsForCustomUrl.app.name.should.equal(getApp().name);
470480

471-
functionsForCustomUrl.app.should.equal(firebase.app());
481+
functionsForCustomUrl.app.should.equal(getApp());
472482

473483
functionsForCustomUrl._customUrlOrRegion.should.equal(customUrl);
474484

@@ -480,21 +490,23 @@ describe('functions() modular', function () {
480490

481491
describe('emulator', function () {
482492
it('configures functions emulator via deprecated method with no port', async function () {
493+
const { getApp } = modular;
483494
const { getFunctions, httpsCallable, connectFunctionsEmulator } = functionsModular;
484495
const region = 'us-central1';
485496
const fnName = 'helloWorldV2';
486497
// const functions = firebase.app().functions(region);
487-
const functions = getFunctions(firebase.app(), region);
498+
const functions = getFunctions(getApp(), region);
488499
connectFunctionsEmulator(functions, 'localhost', 5001);
489500
const response = await httpsCallable(functions, fnName)();
490501
response.data.should.equal('Hello from Firebase!');
491502
});
492503

493504
it('configures functions emulator via deprecated method with port', async function () {
505+
const { getApp } = modular;
494506
const { getFunctions, httpsCallable, connectFunctionsEmulator } = functionsModular;
495507
const region = 'us-central1';
496508
const fnName = 'helloWorldV2';
497-
const functions = getFunctions(firebase.app(), region);
509+
const functions = getFunctions(getApp(), region);
498510
connectFunctionsEmulator(functions, 'localhost', 5001);
499511
const response = await httpsCallable(functions, fnName)();
500512
response.data.should.equal('Hello from Firebase!');
@@ -503,13 +515,14 @@ describe('functions() modular', function () {
503515

504516
describe('httpsCallableFromUrl()', function () {
505517
it('Calls a function by URL', async function () {
518+
const { getApp } = modular;
506519
const { getFunctions, httpsCallableFromUrl } = functionsModular;
507520

508521
let hostname = 'localhost';
509522
if (Platform.android) {
510523
hostname = '10.0.2.2';
511524
}
512-
const functions = getFunctions(firebase.app());
525+
const functions = getFunctions(getApp());
513526
const functionRunner = httpsCallableFromUrl(
514527
functions,
515528
`http://${hostname}:5001/react-native-firebase-testing/us-central1/helloWorldV2`,
@@ -521,73 +534,59 @@ describe('functions() modular', function () {
521534

522535
describe('httpsCallable(fnName)(args)', function () {
523536
it('accepts primitive args: undefined', async function () {
537+
const { getApp } = modular;
524538
const { getFunctions, httpsCallable } = functionsModular;
525-
const functionRunner = httpsCallable(
526-
getFunctions(firebase.app()),
527-
'testFunctionDefaultRegionV2',
528-
);
539+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
529540
const response = await functionRunner();
530541
response.data.should.equal('null');
531542
});
532543

533544
it('accepts primitive args: string', async function () {
545+
const { getApp } = modular;
534546
const { getFunctions, httpsCallable } = functionsModular;
535-
const functionRunner = httpsCallable(
536-
getFunctions(firebase.app()),
537-
'testFunctionDefaultRegionV2',
538-
);
547+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
539548
const response = await functionRunner('hello');
540549
response.data.should.equal('string');
541550
});
542551

543552
it('accepts primitive args: number', async function () {
553+
const { getApp } = modular;
544554
const { getFunctions, httpsCallable } = functionsModular;
545-
const functionRunner = httpsCallable(
546-
getFunctions(firebase.app()),
547-
'testFunctionDefaultRegionV2',
548-
);
555+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
549556
const response = await functionRunner(123);
550557
response.data.should.equal('number');
551558
});
552559

553560
it('accepts primitive args: boolean', async function () {
561+
const { getApp } = modular;
554562
const { getFunctions, httpsCallable } = functionsModular;
555-
const functionRunner = httpsCallable(
556-
getFunctions(firebase.app()),
557-
'testFunctionDefaultRegionV2',
558-
);
563+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
559564
const response = await functionRunner(true);
560565
response.data.should.equal('boolean');
561566
});
562567

563568
it('accepts primitive args: null', async function () {
569+
const { getApp } = modular;
564570
const { getFunctions, httpsCallable } = functionsModular;
565-
const functionRunner = httpsCallable(
566-
getFunctions(firebase.app()),
567-
'testFunctionDefaultRegionV2',
568-
);
571+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
569572
const response = await functionRunner(null);
570573
response.data.should.equal('null');
571574
});
572575

573576
it('accepts array args', async function () {
577+
const { getApp } = modular;
574578
const { getFunctions, httpsCallable } = functionsModular;
575-
const functionRunner = httpsCallable(
576-
getFunctions(firebase.app()),
577-
'testFunctionDefaultRegionV2',
578-
);
579+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
579580
const response = await functionRunner([1, 2, 3, 4]);
580581
response.data.should.equal('array');
581582
});
582583

583584
it('accepts object args', async function () {
585+
const { getApp } = modular;
584586
const { getFunctions, httpsCallable } = functionsModular;
585587
const type = 'object';
586588
const inputData = SAMPLE_DATA[type];
587-
const functionRunner = httpsCallable(
588-
getFunctions(firebase.app()),
589-
'testFunctionDefaultRegionV2',
590-
);
589+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
591590
const { data: outputData } = await functionRunner({
592591
type,
593592
inputData,
@@ -596,13 +595,11 @@ describe('functions() modular', function () {
596595
});
597596

598597
it('accepts complex nested objects', async function () {
598+
const { getApp } = modular;
599599
const { getFunctions, httpsCallable } = functionsModular;
600600
const type = 'deepObject';
601601
const inputData = SAMPLE_DATA[type];
602-
const functionRunner = httpsCallable(
603-
getFunctions(firebase.app()),
604-
'testFunctionDefaultRegionV2',
605-
);
602+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
606603
const { data: outputData } = await functionRunner({
607604
type,
608605
inputData,
@@ -611,13 +608,11 @@ describe('functions() modular', function () {
611608
});
612609

613610
it('accepts complex nested arrays', async function () {
611+
const { getApp } = modular;
614612
const { getFunctions, httpsCallable } = functionsModular;
615613
const type = 'deepArray';
616614
const inputData = SAMPLE_DATA[type];
617-
const functionRunner = httpsCallable(
618-
getFunctions(firebase.app()),
619-
'testFunctionDefaultRegionV2',
620-
);
615+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
621616
const { data: outputData } = await functionRunner({
622617
type,
623618
inputData,
@@ -628,11 +623,9 @@ describe('functions() modular', function () {
628623

629624
describe('HttpsError', function () {
630625
it('errors return instance of HttpsError', async function () {
626+
const { getApp } = modular;
631627
const { getFunctions, httpsCallable } = functionsModular;
632-
const functionRunner = httpsCallable(
633-
getFunctions(firebase.app()),
634-
'testFunctionDefaultRegionV2',
635-
);
628+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
636629

637630
try {
638631
await functionRunner({});
@@ -649,11 +642,9 @@ describe('functions() modular', function () {
649642
it('HttpsError.details -> allows returning complex data', async function () {
650643
let type = 'deepObject';
651644
let inputData = SAMPLE_DATA[type];
645+
const { getApp } = modular;
652646
const { getFunctions, httpsCallable } = functionsModular;
653-
const functionRunner = httpsCallable(
654-
getFunctions(firebase.app()),
655-
'testFunctionDefaultRegionV2',
656-
);
647+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
657648
try {
658649
await functionRunner({
659650
type,
@@ -690,13 +681,11 @@ describe('functions() modular', function () {
690681
});
691682

692683
it('HttpsError.details -> allows returning primitives', async function () {
684+
const { getApp } = modular;
693685
const { getFunctions, httpsCallable } = functionsModular;
694686
let type = 'number';
695687
let inputData = SAMPLE_DATA[type];
696-
const functionRunner = httpsCallable(
697-
getFunctions(firebase.app()),
698-
'testFunctionDefaultRegionV2',
699-
);
688+
const functionRunner = httpsCallable(getFunctions(getApp()), 'testFunctionDefaultRegionV2');
700689
try {
701690
await functionRunner({
702691
type,
@@ -767,8 +756,9 @@ describe('functions() modular', function () {
767756
});
768757

769758
it('HttpsCallableOptions.timeout will error when timeout is exceeded', async function () {
759+
const { getApp } = modular;
770760
const { getFunctions, httpsCallable } = functionsModular;
771-
const functions = getFunctions(firebase.app());
761+
const functions = getFunctions(getApp());
772762
const functionRunner = httpsCallable(functions, 'sleeperV2', { timeout: 1000 });
773763

774764
try {

0 commit comments

Comments
 (0)