1919import path = require( 'path' ) ;
2020import * as _ from 'lodash' ;
2121import { expect } from 'chai' ;
22+ import * as utils from '../../../src/utils/index' ;
2223
2324import * as mocks from '../../resources/mocks' ;
2425import { FirebaseApp } from '../../../src/firebase-app' ;
@@ -33,6 +34,7 @@ describe('Firestore', () => {
3334 let firestore : any ;
3435
3536 let appCredentials : string ;
37+ let googleCloudProject : string ;
3638 let gcloudProject : string ;
3739
3840 const invalidCredError = 'Failed to initialize Google Cloud Firestore client with the available '
@@ -43,6 +45,7 @@ describe('Firestore', () => {
4345
4446 beforeEach ( ( ) => {
4547 appCredentials = process . env . GOOGLE_APPLICATION_CREDENTIALS ;
48+ googleCloudProject = process . env . GOOGLE_CLOUD_PROJECT ;
4649 gcloudProject = process . env . GCLOUD_PROJECT ;
4750 delete process . env . GOOGLE_APPLICATION_CREDENTIALS ;
4851
@@ -60,7 +63,16 @@ describe('Firestore', () => {
6063
6164 afterEach ( ( ) => {
6265 process . env . GOOGLE_APPLICATION_CREDENTIALS = appCredentials ;
63- process . env . GCLOUD_PROJECT = gcloudProject ;
66+ if ( googleCloudProject ) {
67+ process . env . GOOGLE_CLOUD_PROJECT = googleCloudProject ;
68+ } else {
69+ delete process . env . GOOGLE_CLOUD_PROJECT ;
70+ }
71+ if ( gcloudProject ) {
72+ process . env . GCLOUD_PROJECT = gcloudProject ;
73+ } else {
74+ delete process . env . GCLOUD_PROJECT ;
75+ }
6476 return mockApp . delete ( ) ;
6577 } ) ;
6678
@@ -84,14 +96,15 @@ describe('Firestore', () => {
8496
8597 it ( 'should throw given an invalid credential with project ID' , ( ) => {
8698 // Project ID is read from the environment variable, but the credential is unsupported.
87- process . env . GCLOUD_PROJECT = 'project_id' ;
99+ process . env . GOOGLE_CLOUD_PROJECT = 'project_id' ;
88100 expect ( ( ) => {
89101 return new FirestoreService ( mockCredentialApp ) ;
90102 } ) . to . throw ( invalidCredError ) ;
91103 } ) ;
92104
93105 it ( 'should throw given an invalid credential without project ID' , ( ) => {
94106 // Project ID not set in the environment.
107+ delete process . env . GOOGLE_CLOUD_PROJECT ;
95108 delete process . env . GCLOUD_PROJECT ;
96109 expect ( ( ) => {
97110 return new FirestoreService ( mockCredentialApp ) ;
@@ -106,6 +119,7 @@ describe('Firestore', () => {
106119
107120 it ( 'should not throw given application default credentials without project ID' , ( ) => {
108121 // Project ID not set in the environment.
122+ delete process . env . GOOGLE_CLOUD_PROJECT ;
109123 delete process . env . GCLOUD_PROJECT ;
110124 process . env . GOOGLE_APPLICATION_CREDENTIALS = mockServiceAccount ;
111125 expect ( ( ) => {
@@ -151,7 +165,14 @@ describe('Firestore', () => {
151165 expect ( options . projectId ) . to . equal ( 'explicit-project-id' ) ;
152166 } ) ;
153167
154- it ( 'should return a string when project ID is present in environment' , ( ) => {
168+ it ( 'should return a string when GOOGLE_CLOUD_PROJECT is set' , ( ) => {
169+ process . env . GOOGLE_CLOUD_PROJECT = 'env-project-id' ;
170+ process . env . GOOGLE_APPLICATION_CREDENTIALS = mockServiceAccount ;
171+ const options = getFirestoreOptions ( defaultCredentialApp ) ;
172+ expect ( options . projectId ) . to . equal ( 'env-project-id' ) ;
173+ } ) ;
174+
175+ it ( 'should return a string when GCLOUD_PROJECT is set' , ( ) => {
155176 process . env . GCLOUD_PROJECT = 'env-project-id' ;
156177 process . env . GOOGLE_APPLICATION_CREDENTIALS = mockServiceAccount ;
157178 const options = getFirestoreOptions ( defaultCredentialApp ) ;
0 commit comments