@@ -32,7 +32,7 @@ describe('Database Functions', () => {
3232
3333 before ( ( ) => {
3434 process . env . FIREBASE_CONFIG = JSON . stringify ( {
35- databaseURL : 'https://subdomain.firebaseio.com ' ,
35+ databaseURL : 'https://subdomain.apse.firebasedatabase.app ' ,
3636 } ) ;
3737 appsNamespace . init ( ) ;
3838 } ) ;
@@ -424,29 +424,51 @@ describe('Database Functions', () => {
424424 } ) ;
425425 } ) ;
426426
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
431432 ) ;
432433 expect ( instance ) . to . equal ( 'https://foo.firebaseio.com' ) ;
433434 expect ( path ) . to . equal ( '/bar' ) ;
434435 } ) ;
435436
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+
436455 it ( 'should throw an error if the given instance name contains anything except alphanumerics and dashes' , ( ) => {
437456 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
440460 ) ;
441461 } ) . to . throw ( Error ) ;
442462 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
445466 ) ;
446467 } ) . to . throw ( Error ) ;
447468 expect ( ( ) => {
448- return database . resourceToInstanceAndPath (
449- 'projects/_/instances/BAD!!!!/refs/bar'
469+ return database . extractInstanceAndPath (
470+ 'projects/_/instances/BAD!!!!/refs/bar' ,
471+ undefined
450472 ) ;
451473 } ) . to . throw ( Error ) ;
452474 } ) ;
@@ -457,8 +479,9 @@ describe('Database Functions', () => {
457479 const apps = new appsNamespace . Apps ( ) ;
458480
459481 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'
462485 ) ;
463486 subject = new database . DataSnapshot ( data , path , apps . admin , instance ) ;
464487 } ;
@@ -467,7 +490,7 @@ describe('Database Functions', () => {
467490 it ( 'should return a ref for correct instance, not the default instance' , ( ) => {
468491 populate ( { } ) ;
469492 expect ( subject . ref . toJSON ( ) ) . to . equal (
470- 'https://other-subdomain.firebaseio.com/foo'
493+ 'https://other-subdomain.firebaseio-staging .com/foo'
471494 ) ;
472495 } ) ;
473496 } ) ;
@@ -648,8 +671,9 @@ describe('Database Functions', () => {
648671 } ) ;
649672
650673 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
653677 ) ;
654678 const snapshot = new database . DataSnapshot (
655679 null ,
0 commit comments