@@ -32,7 +32,7 @@ describe('Database Functions', () => {
32
32
33
33
before ( ( ) => {
34
34
process . env . FIREBASE_CONFIG = JSON . stringify ( {
35
- databaseURL : 'https://subdomain.firebaseio.com ' ,
35
+ databaseURL : 'https://subdomain.apse.firebasedatabase.app ' ,
36
36
} ) ;
37
37
appsNamespace . init ( ) ;
38
38
} ) ;
@@ -424,29 +424,51 @@ describe('Database Functions', () => {
424
424
} ) ;
425
425
} ) ;
426
426
427
- describe ( 'resourceToInstanceAndPath' , ( ) => {
428
- it ( 'should return the correct instance and path strings' , ( ) => {
429
- const [ instance , path ] = database . resourceToInstanceAndPath (
430
- 'projects/_/instances/foo/refs/bar'
427
+ describe ( 'extractInstanceAndPath' , ( ) => {
428
+ it ( 'should return correct us-central prod instance and path strings if domain is missing' , ( ) => {
429
+ const [ instance , path ] = database . extractInstanceAndPath (
430
+ 'projects/_/instances/foo/refs/bar' ,
431
+ undefined
431
432
) ;
432
433
expect ( instance ) . to . equal ( 'https://foo.firebaseio.com' ) ;
433
434
expect ( path ) . to . equal ( '/bar' ) ;
434
435
} ) ;
435
436
437
+ it ( 'should return the correct staging instance and path strings if domain is present' , ( ) => {
438
+ const [ instance , path ] = database . extractInstanceAndPath (
439
+ 'projects/_/instances/foo/refs/bar' ,
440
+ 'firebaseio-staging.com'
441
+ ) ;
442
+ expect ( instance ) . to . equal ( 'https://foo.firebaseio-staging.com' ) ;
443
+ expect ( path ) . to . equal ( '/bar' ) ;
444
+ } ) ;
445
+
446
+ it ( 'should return the correct multi-region instance and path strings if domain is present' , ( ) => {
447
+ const [ instance , path ] = database . extractInstanceAndPath (
448
+ 'projects/_/instances/foo/refs/bar' ,
449
+ 'euw1.firebasedatabase.app'
450
+ ) ;
451
+ expect ( instance ) . to . equal ( 'https://foo.euw1.firebasedatabase.app' ) ;
452
+ expect ( path ) . to . equal ( '/bar' ) ;
453
+ } ) ;
454
+
436
455
it ( 'should throw an error if the given instance name contains anything except alphanumerics and dashes' , ( ) => {
437
456
expect ( ( ) => {
438
- return database . resourceToInstanceAndPath (
439
- 'projects/_/instances/a.bad.name/refs/bar'
457
+ return database . extractInstanceAndPath (
458
+ 'projects/_/instances/a.bad.name/refs/bar' ,
459
+ undefined
440
460
) ;
441
461
} ) . to . throw ( Error ) ;
442
462
expect ( ( ) => {
443
- return database . resourceToInstanceAndPath (
444
- 'projects/_/instances/a_different_bad_name/refs/bar'
463
+ return database . extractInstanceAndPath (
464
+ 'projects/_/instances/a_different_bad_name/refs/bar' ,
465
+ undefined
445
466
) ;
446
467
} ) . to . throw ( Error ) ;
447
468
expect ( ( ) => {
448
- return database . resourceToInstanceAndPath (
449
- 'projects/_/instances/BAD!!!!/refs/bar'
469
+ return database . extractInstanceAndPath (
470
+ 'projects/_/instances/BAD!!!!/refs/bar' ,
471
+ undefined
450
472
) ;
451
473
} ) . to . throw ( Error ) ;
452
474
} ) ;
@@ -457,8 +479,9 @@ describe('Database Functions', () => {
457
479
const apps = new appsNamespace . Apps ( ) ;
458
480
459
481
const populate = ( data : any ) => {
460
- const [ instance , path ] = database . resourceToInstanceAndPath (
461
- 'projects/_/instances/other-subdomain/refs/foo'
482
+ const [ instance , path ] = database . extractInstanceAndPath (
483
+ 'projects/_/instances/other-subdomain/refs/foo' ,
484
+ 'firebaseio-staging.com'
462
485
) ;
463
486
subject = new database . DataSnapshot ( data , path , apps . admin , instance ) ;
464
487
} ;
@@ -467,7 +490,7 @@ describe('Database Functions', () => {
467
490
it ( 'should return a ref for correct instance, not the default instance' , ( ) => {
468
491
populate ( { } ) ;
469
492
expect ( subject . ref . toJSON ( ) ) . to . equal (
470
- 'https://other-subdomain.firebaseio.com/foo'
493
+ 'https://other-subdomain.firebaseio-staging .com/foo'
471
494
) ;
472
495
} ) ;
473
496
} ) ;
@@ -648,8 +671,9 @@ describe('Database Functions', () => {
648
671
} ) ;
649
672
650
673
it ( 'should return null for the root' , ( ) => {
651
- const [ instance , path ] = database . resourceToInstanceAndPath (
652
- 'projects/_/instances/foo/refs/'
674
+ const [ instance , path ] = database . extractInstanceAndPath (
675
+ 'projects/_/instances/foo/refs/' ,
676
+ undefined
653
677
) ;
654
678
const snapshot = new database . DataSnapshot (
655
679
null ,
0 commit comments