Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
How to test firebase callable function with firestore

I have a firebase callable function like

exports.getUserInfo = functions.https.onCall(async (data, context) => {
        const userIdRef = store.collection('UserID').doc('Document');
        let res = null;
        try {
            res = await store.runTransaction(async t => {
                const doc = await t.get(userIdRef);
                currentUserId = doc.data().ID;


                const newUserIdNum = currentUserId + 1;
                await t.update(userIdRef, {ID: newUserIdNum});
                let initUserData = {
                    'userID': newUserId,
                }
                return initUserData ;
            });
            console.log('Transaction success');
        } catch (e) {
            console.error('Transaction failure:', e);
        }

        return res;
})

but I am not sure how to create unit test about this. I want to mock UserID/Documment before I call test.wrap(getUserInfo), like

const myFunctions = require('../index.js')
const getUserInfoWrapped = test.wrap(myFunctions.getUserInfo);

var assert = require('assert');
describe('User', function() {
        describe('getUserInfo()', function() {
                it('should create user', async function() {
                        // sample code, this won't work
                        const snapshot = test.firestore.makeDocumentSnapshot({ID: 1001}, 'UserID/Document');
                        const data = {}
                        const result = await getUserInfoWrapped (data, {});
                        assert.equal(result.userID, "1002");
                });
        });
});

seems this case not covered by firebase document

Reference:

  • https://firebase.google.com/docs/functions/unit-testing
  • https://github.com/firebase/firebase-functions-test/blob/c77aa92d345b8e4fb5ad98534989eb8dcf7d9bc4/spec/providers/https.spec.ts
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!