@@ -90,6 +90,16 @@ const SAMPLE_DATA = {
90
90
91
91
describe ( 'functions() modular' , function ( ) {
92
92
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
+
93
103
describe ( 'namespace' , function ( ) {
94
104
it ( 'accepts passing in an FirebaseApp instance as first arg' , async function ( ) {
95
105
const appName = `functionsApp${ FirebaseHelpers . id } 2` ;
@@ -407,27 +417,25 @@ describe('functions() modular', function () {
407
417
describe ( 'modular' , function ( ) {
408
418
describe ( 'getFunctions' , function ( ) {
409
419
it ( 'pass app as argument' , function ( ) {
420
+ const { getApp } = modular ;
410
421
const { getFunctions } = functionsModular ;
411
-
412
- const functions = getFunctions ( firebase . app ( ) ) ;
413
-
422
+ const functions = getFunctions ( getApp ( ) ) ;
414
423
functions . constructor . name . should . be . equal ( 'FirebaseFunctionsModule' ) ;
415
424
} ) ;
416
425
417
426
it ( 'no app as argument' , function ( ) {
418
427
const { getFunctions } = functionsModular ;
419
-
420
428
const functions = getFunctions ( ) ;
421
-
422
429
functions . constructor . name . should . be . equal ( 'FirebaseFunctionsModule' ) ;
423
430
} ) ;
424
431
} ) ;
425
432
426
433
it ( 'accepts passing in an FirebaseApp instance as first arg' , async function ( ) {
434
+ const { initializeApp } = modular ;
427
435
const { getFunctions } = functionsModular ;
428
436
const appName = `functionsApp${ FirebaseHelpers . id } 3` ;
429
437
const platformAppConfig = FirebaseHelpers . app . config ( ) ;
430
- const app = await firebase . initializeApp ( platformAppConfig , appName ) ;
438
+ const app = await initializeApp ( platformAppConfig , appName ) ;
431
439
const functions = getFunctions ( app ) ;
432
440
433
441
functions . app . should . equal ( app ) ;
@@ -439,18 +447,19 @@ describe('functions() modular', function () {
439
447
} ) ;
440
448
441
449
it ( 'accepts passing in a region string as first arg to an app' , async function ( ) {
450
+ const { getApp } = modular ;
442
451
const { getFunctions } = functionsModular ;
443
452
const region = 'europe-west1' ;
444
453
445
- const functionsForRegion = getFunctions ( firebase . app ( ) , region ) ;
454
+ const functionsForRegion = getFunctions ( getApp ( ) , region ) ;
446
455
447
456
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 ) ;
450
459
451
- firebase . app ( ) . functions ( region ) . app . should . equal ( firebase . app ( ) ) ;
460
+ getApp ( ) . functions ( region ) . app . should . equal ( getApp ( ) ) ;
452
461
453
- firebase . app ( ) . functions ( region ) . _customUrlOrRegion . should . equal ( region ) ;
462
+ getApp ( ) . functions ( region ) . _customUrlOrRegion . should . equal ( region ) ;
454
463
455
464
const functionRunner = functionsForRegion . httpsCallable ( 'testFunctionCustomRegion' ) ;
456
465
@@ -459,16 +468,17 @@ describe('functions() modular', function () {
459
468
} ) ;
460
469
461
470
it ( 'accepts passing in a custom url string as first arg to an app' , async function ( ) {
471
+ const { getApp } = modular ;
462
472
const { getFunctions } = functionsModular ;
463
473
const customUrl = 'https://us-central1-react-native-firebase-testing.cloudfunctions.net' ;
464
474
465
- const functionsForCustomUrl = getFunctions ( firebase . app ( ) , customUrl ) ;
475
+ const functionsForCustomUrl = getFunctions ( getApp ( ) , customUrl ) ;
466
476
467
477
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 ) ;
470
480
471
- functionsForCustomUrl . app . should . equal ( firebase . app ( ) ) ;
481
+ functionsForCustomUrl . app . should . equal ( getApp ( ) ) ;
472
482
473
483
functionsForCustomUrl . _customUrlOrRegion . should . equal ( customUrl ) ;
474
484
@@ -480,21 +490,23 @@ describe('functions() modular', function () {
480
490
481
491
describe ( 'emulator' , function ( ) {
482
492
it ( 'configures functions emulator via deprecated method with no port' , async function ( ) {
493
+ const { getApp } = modular ;
483
494
const { getFunctions, httpsCallable, connectFunctionsEmulator } = functionsModular ;
484
495
const region = 'us-central1' ;
485
496
const fnName = 'helloWorldV2' ;
486
497
// const functions = firebase.app().functions(region);
487
- const functions = getFunctions ( firebase . app ( ) , region ) ;
498
+ const functions = getFunctions ( getApp ( ) , region ) ;
488
499
connectFunctionsEmulator ( functions , 'localhost' , 5001 ) ;
489
500
const response = await httpsCallable ( functions , fnName ) ( ) ;
490
501
response . data . should . equal ( 'Hello from Firebase!' ) ;
491
502
} ) ;
492
503
493
504
it ( 'configures functions emulator via deprecated method with port' , async function ( ) {
505
+ const { getApp } = modular ;
494
506
const { getFunctions, httpsCallable, connectFunctionsEmulator } = functionsModular ;
495
507
const region = 'us-central1' ;
496
508
const fnName = 'helloWorldV2' ;
497
- const functions = getFunctions ( firebase . app ( ) , region ) ;
509
+ const functions = getFunctions ( getApp ( ) , region ) ;
498
510
connectFunctionsEmulator ( functions , 'localhost' , 5001 ) ;
499
511
const response = await httpsCallable ( functions , fnName ) ( ) ;
500
512
response . data . should . equal ( 'Hello from Firebase!' ) ;
@@ -503,13 +515,14 @@ describe('functions() modular', function () {
503
515
504
516
describe ( 'httpsCallableFromUrl()' , function ( ) {
505
517
it ( 'Calls a function by URL' , async function ( ) {
518
+ const { getApp } = modular ;
506
519
const { getFunctions, httpsCallableFromUrl } = functionsModular ;
507
520
508
521
let hostname = 'localhost' ;
509
522
if ( Platform . android ) {
510
523
hostname = '10.0.2.2' ;
511
524
}
512
- const functions = getFunctions ( firebase . app ( ) ) ;
525
+ const functions = getFunctions ( getApp ( ) ) ;
513
526
const functionRunner = httpsCallableFromUrl (
514
527
functions ,
515
528
`http://${ hostname } :5001/react-native-firebase-testing/us-central1/helloWorldV2` ,
@@ -521,73 +534,59 @@ describe('functions() modular', function () {
521
534
522
535
describe ( 'httpsCallable(fnName)(args)' , function ( ) {
523
536
it ( 'accepts primitive args: undefined' , async function ( ) {
537
+ const { getApp } = modular ;
524
538
const { getFunctions, httpsCallable } = functionsModular ;
525
- const functionRunner = httpsCallable (
526
- getFunctions ( firebase . app ( ) ) ,
527
- 'testFunctionDefaultRegionV2' ,
528
- ) ;
539
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
529
540
const response = await functionRunner ( ) ;
530
541
response . data . should . equal ( 'null' ) ;
531
542
} ) ;
532
543
533
544
it ( 'accepts primitive args: string' , async function ( ) {
545
+ const { getApp } = modular ;
534
546
const { getFunctions, httpsCallable } = functionsModular ;
535
- const functionRunner = httpsCallable (
536
- getFunctions ( firebase . app ( ) ) ,
537
- 'testFunctionDefaultRegionV2' ,
538
- ) ;
547
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
539
548
const response = await functionRunner ( 'hello' ) ;
540
549
response . data . should . equal ( 'string' ) ;
541
550
} ) ;
542
551
543
552
it ( 'accepts primitive args: number' , async function ( ) {
553
+ const { getApp } = modular ;
544
554
const { getFunctions, httpsCallable } = functionsModular ;
545
- const functionRunner = httpsCallable (
546
- getFunctions ( firebase . app ( ) ) ,
547
- 'testFunctionDefaultRegionV2' ,
548
- ) ;
555
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
549
556
const response = await functionRunner ( 123 ) ;
550
557
response . data . should . equal ( 'number' ) ;
551
558
} ) ;
552
559
553
560
it ( 'accepts primitive args: boolean' , async function ( ) {
561
+ const { getApp } = modular ;
554
562
const { getFunctions, httpsCallable } = functionsModular ;
555
- const functionRunner = httpsCallable (
556
- getFunctions ( firebase . app ( ) ) ,
557
- 'testFunctionDefaultRegionV2' ,
558
- ) ;
563
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
559
564
const response = await functionRunner ( true ) ;
560
565
response . data . should . equal ( 'boolean' ) ;
561
566
} ) ;
562
567
563
568
it ( 'accepts primitive args: null' , async function ( ) {
569
+ const { getApp } = modular ;
564
570
const { getFunctions, httpsCallable } = functionsModular ;
565
- const functionRunner = httpsCallable (
566
- getFunctions ( firebase . app ( ) ) ,
567
- 'testFunctionDefaultRegionV2' ,
568
- ) ;
571
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
569
572
const response = await functionRunner ( null ) ;
570
573
response . data . should . equal ( 'null' ) ;
571
574
} ) ;
572
575
573
576
it ( 'accepts array args' , async function ( ) {
577
+ const { getApp } = modular ;
574
578
const { getFunctions, httpsCallable } = functionsModular ;
575
- const functionRunner = httpsCallable (
576
- getFunctions ( firebase . app ( ) ) ,
577
- 'testFunctionDefaultRegionV2' ,
578
- ) ;
579
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
579
580
const response = await functionRunner ( [ 1 , 2 , 3 , 4 ] ) ;
580
581
response . data . should . equal ( 'array' ) ;
581
582
} ) ;
582
583
583
584
it ( 'accepts object args' , async function ( ) {
585
+ const { getApp } = modular ;
584
586
const { getFunctions, httpsCallable } = functionsModular ;
585
587
const type = 'object' ;
586
588
const inputData = SAMPLE_DATA [ type ] ;
587
- const functionRunner = httpsCallable (
588
- getFunctions ( firebase . app ( ) ) ,
589
- 'testFunctionDefaultRegionV2' ,
590
- ) ;
589
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
591
590
const { data : outputData } = await functionRunner ( {
592
591
type,
593
592
inputData,
@@ -596,13 +595,11 @@ describe('functions() modular', function () {
596
595
} ) ;
597
596
598
597
it ( 'accepts complex nested objects' , async function ( ) {
598
+ const { getApp } = modular ;
599
599
const { getFunctions, httpsCallable } = functionsModular ;
600
600
const type = 'deepObject' ;
601
601
const inputData = SAMPLE_DATA [ type ] ;
602
- const functionRunner = httpsCallable (
603
- getFunctions ( firebase . app ( ) ) ,
604
- 'testFunctionDefaultRegionV2' ,
605
- ) ;
602
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
606
603
const { data : outputData } = await functionRunner ( {
607
604
type,
608
605
inputData,
@@ -611,13 +608,11 @@ describe('functions() modular', function () {
611
608
} ) ;
612
609
613
610
it ( 'accepts complex nested arrays' , async function ( ) {
611
+ const { getApp } = modular ;
614
612
const { getFunctions, httpsCallable } = functionsModular ;
615
613
const type = 'deepArray' ;
616
614
const inputData = SAMPLE_DATA [ type ] ;
617
- const functionRunner = httpsCallable (
618
- getFunctions ( firebase . app ( ) ) ,
619
- 'testFunctionDefaultRegionV2' ,
620
- ) ;
615
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
621
616
const { data : outputData } = await functionRunner ( {
622
617
type,
623
618
inputData,
@@ -628,11 +623,9 @@ describe('functions() modular', function () {
628
623
629
624
describe ( 'HttpsError' , function ( ) {
630
625
it ( 'errors return instance of HttpsError' , async function ( ) {
626
+ const { getApp } = modular ;
631
627
const { getFunctions, httpsCallable } = functionsModular ;
632
- const functionRunner = httpsCallable (
633
- getFunctions ( firebase . app ( ) ) ,
634
- 'testFunctionDefaultRegionV2' ,
635
- ) ;
628
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
636
629
637
630
try {
638
631
await functionRunner ( { } ) ;
@@ -649,11 +642,9 @@ describe('functions() modular', function () {
649
642
it ( 'HttpsError.details -> allows returning complex data' , async function ( ) {
650
643
let type = 'deepObject' ;
651
644
let inputData = SAMPLE_DATA [ type ] ;
645
+ const { getApp } = modular ;
652
646
const { getFunctions, httpsCallable } = functionsModular ;
653
- const functionRunner = httpsCallable (
654
- getFunctions ( firebase . app ( ) ) ,
655
- 'testFunctionDefaultRegionV2' ,
656
- ) ;
647
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
657
648
try {
658
649
await functionRunner ( {
659
650
type,
@@ -690,13 +681,11 @@ describe('functions() modular', function () {
690
681
} ) ;
691
682
692
683
it ( 'HttpsError.details -> allows returning primitives' , async function ( ) {
684
+ const { getApp } = modular ;
693
685
const { getFunctions, httpsCallable } = functionsModular ;
694
686
let type = 'number' ;
695
687
let inputData = SAMPLE_DATA [ type ] ;
696
- const functionRunner = httpsCallable (
697
- getFunctions ( firebase . app ( ) ) ,
698
- 'testFunctionDefaultRegionV2' ,
699
- ) ;
688
+ const functionRunner = httpsCallable ( getFunctions ( getApp ( ) ) , 'testFunctionDefaultRegionV2' ) ;
700
689
try {
701
690
await functionRunner ( {
702
691
type,
@@ -767,8 +756,9 @@ describe('functions() modular', function () {
767
756
} ) ;
768
757
769
758
it ( 'HttpsCallableOptions.timeout will error when timeout is exceeded' , async function ( ) {
759
+ const { getApp } = modular ;
770
760
const { getFunctions, httpsCallable } = functionsModular ;
771
- const functions = getFunctions ( firebase . app ( ) ) ;
761
+ const functions = getFunctions ( getApp ( ) ) ;
772
762
const functionRunner = httpsCallable ( functions , 'sleeperV2' , { timeout : 1000 } ) ;
773
763
774
764
try {
0 commit comments