Skip to content

Commit cec9ba7

Browse files
authored
Merge pull request #249 from firebase/client-project-id
docs: adds ex for creating client w optional projectId
2 parents 7ef1392 + 1036e99 commit cec9ba7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

‎firestore/main/index.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
const debug = require('debug')('firestore-snippets-node');
22

33
// [START firestore_deps]
4+
// [START firestore_setup_client_create]
45
const admin = require('firebase-admin');
56
// [END firestore_deps]
7+
// [END firestore_setup_client_create]
8+
69

710
// We supress these logs when not in NODE_ENV=debug for cleaner Mocha output
811
const console = {log: debug};
912

13+
async function initializeAppWithProjectId() {
14+
// [START firestore_setup_client_create]
15+
admin.initializeApp({
16+
// The `projectId` parameter is optional and represents which project the
17+
// client will act on behalf of. If not supplied, it falls back to the default
18+
// project inferred from the environment.
19+
projectId: 'my-project-id',
20+
});
21+
const db = admin.firestore();
22+
// [END firestore_setup_client_create]
23+
return db;
24+
}
25+
1026
async function initializeApp() {
1127
process.env.GCLOUD_PROJECT = 'firestorebeta1test2';
1228
// [START initialize_app]
@@ -17,6 +33,8 @@ async function initializeApp() {
1733

1834
const db = admin.firestore();
1935
// [END initialize_app]
36+
await db.terminate();
37+
// Destroy connection so we can run other tests that initialize the default app.
2038
return db;
2139
}
2240

@@ -944,8 +962,12 @@ async function deleteQueryBatch(db, query, resolve) {
944962

945963
describe('Firestore Smoketests', () => {
946964

947-
admin.initializeApp();
948-
const db = admin.firestore();
965+
const app = admin.initializeApp({}, 'tests');
966+
const db = admin.firestore(app);
967+
968+
it('should initialize a db with the default credential', () => {
969+
return initializeApp();
970+
});
949971

950972
it('should get an empty document', () => {
951973
return getDocumentEmpty(db);

0 commit comments

Comments
 (0)