@@ -304,6 +304,7 @@ describe('instantiation', () => {
304304
305305 /* eslint-disable @typescript-eslint/no-explicit-any */
306306 expect ( ( firestore as any ) . _settings . projectId ) . to . equal ( PROJECT_ID ) ;
307+ expect ( ( firestore as any ) . _settings . databaseId ) . to . be . undefined ;
307308 expect ( ( firestore as any ) . _settings . foo ) . to . equal ( 'bar' ) ;
308309 /* eslint-enable @typescript-eslint/no-explicit-any */
309310 } ) ;
@@ -343,6 +344,23 @@ describe('instantiation', () => {
343344 ) ;
344345 } ) ;
345346
347+ it ( 'validates database ID is string' , ( ) => {
348+ expect ( ( ) => {
349+ const settings = { ...DEFAULT_SETTINGS , databaseId : 1337 } ;
350+ new Firestore . Firestore ( settings as InvalidApiUsage ) ;
351+ } ) . to . throw (
352+ 'Value for argument "settings.databaseId" is not a valid string.'
353+ ) ;
354+
355+ expect ( ( ) => {
356+ new Firestore . Firestore ( DEFAULT_SETTINGS ) . settings ( {
357+ databaseId : 1337 ,
358+ } as InvalidApiUsage ) ;
359+ } ) . to . throw (
360+ 'Value for argument "settings.databaseId" is not a valid string.'
361+ ) ;
362+ } ) ;
363+
346364 it ( 'validates ssl is a boolean' , ( ) => {
347365 const invalidValues = [ 'true' , 1337 ] ;
348366
@@ -548,11 +566,14 @@ describe('instantiation', () => {
548566 new Firestore . Firestore ( { maxIdleChannels : 1 } ) ;
549567 } ) ;
550568
551- it ( 'uses project id from constructor' , ( ) => {
552- const firestore = new Firestore . Firestore ( { projectId : 'foo' } ) ;
569+ it ( 'uses project id and database id from constructor' , ( ) => {
570+ const firestore = new Firestore . Firestore ( {
571+ projectId : 'foo' ,
572+ databaseId : 'bar' ,
573+ } ) ;
553574
554575 return expect ( firestore . formattedName ) . to . equal (
555- 'projects/foo/databases/(default) '
576+ 'projects/foo/databases/bar '
556577 ) ;
557578 } ) ;
558579
@@ -571,7 +592,7 @@ describe('instantiation', () => {
571592 } ) ;
572593 } ) ;
573594
574- it ( 'uses project ID from settings()' , ( ) => {
595+ it ( 'uses project ID from settings() and default database ID ' , ( ) => {
575596 const firestore = new Firestore . Firestore ( {
576597 sslCreds : grpc . credentials . createInsecure ( ) ,
577598 } ) ;
@@ -583,6 +604,18 @@ describe('instantiation', () => {
583604 ) ;
584605 } ) ;
585606
607+ it ( 'uses database ID and database ID from settings()' , ( ) => {
608+ const firestore = new Firestore . Firestore ( {
609+ sslCreds : grpc . credentials . createInsecure ( ) ,
610+ } ) ;
611+
612+ firestore . settings ( { projectId : PROJECT_ID , databaseId : 'bar' } ) ;
613+
614+ expect ( firestore . formattedName ) . to . equal (
615+ `projects/${ PROJECT_ID } /databases/bar`
616+ ) ;
617+ } ) ;
618+
586619 it ( 'handles error from project ID detection' , ( ) => {
587620 return createInstance (
588621 {
0 commit comments