Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't determine Firebase Database URL." when initialize Admin SDK #171

Open
ASE55471 opened this issue Sep 11, 2022 · 3 comments
Open

"Can't determine Firebase Database URL." when initialize Admin SDK #171

ASE55471 opened this issue Sep 11, 2022 · 3 comments

Comments

@ASE55471
Copy link

Version info

**firebase-functions-test:"^2.4.0"

**firebase-functions:"^3.23.0"

**firebase-admin:"^11.0.1"

Test case

function code

import { https } from 'firebase-functions';
import { Timestamp } from 'firebase-admin/firestore';
import * as admin from 'firebase-admin';
admin.initializeApp();

let defaultDatabase = admin.database();
let defaultFirestore = admin.firestore();

test code

import { test } from "@jest/globals";
import { functionF} from "../../src/functionF";
import firebaseFunctionsTest from "firebase-functions-test";

const {wrap , firestore} = firebaseFunctionsTest({
    projectId: 'project-id',
    storageBucket: 'project-id.appspot.com',
    databaseURL: "https://project-id-default-rtdb.asia-southeast1.firebasedatabase.app",
}, './serviceAccountkey.json');


describe('test1', () => {
    test('test', () => {
        const wrappedFunctionF = wrap(functionF);
        const snap = firestore.makeDocumentSnapshot({ foo: 'bar' }, 'document/path');
        wrappedFunctionF(snap);
    });
});

I tried fill databaseURL without "-default-rtdb" but still throw same error.

Relative StackOverflow question I asked: https://stackoverflow.com/questions/73657752/how-to-initialize-admin-sdk-with-firebase-functions-test

Expected behavior

Finish the test without error .

Actual behavior

It throw error.

    Can't determine Firebase Database URL.

      4 | admin.initializeApp();
      5 |
    > 6 | let defaultDatabase = admin.database();
        |                             ^
      7 | let defaultFirestore = admin.firestore();
      8 |
@josephepia
Copy link

@ASE55471 did you find any solution?

@ASE55471
Copy link
Author

@josephepia No, I still have no ideas on this issue.

@josephepia
Copy link

@ASE55471 my workaround was to manually add the database url to the index.ts file and then remove it before submitting a production.

functions/src/index.ts

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";

admin.initializeApp({
  databaseURL: "http://127.0.0.1:9000/?ns=nameProject-default-rtdb", //<- add and remove 
});

It can be improved with a condition where it checks if it is in the emulator environment with FUNCTIONS_EMULATOR==true How to detect if environment is development or production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants