firebase-functions-test icon indicating copy to clipboard operation
firebase-functions-test copied to clipboard

makeDocumentSnapshot: TypeError: firestoreService.snapshot_ is not a function

Open tettoffensive opened this issue 4 years ago • 10 comments

I get the following error when trying to use makeDocumentSnapshot: TypeError: firestoreService.snapshot_ is not a function

It seems that it has to do with the following line: https://github.com/firebase/firebase-functions-test/blob/2574781e959ab019c3e3823a59c26f9b30d65a6c/src/providers/firestore.ts#L83

My code is as follows:

import FunctionsTest from 'firebase-functions-test';
import onUserWritten from '../onUserWritten.function';

const test = FunctionsTest();

describe('onUserWritten', () => {
  it('should do stuff', async () => {
    const wrapped = test.wrap(onUserWritten);

    const beforeSnap = test.firestore.makeDocumentSnapshot(
      {
        id: 'testUser',
        email: '[email protected]',
      },
      '/users/testUser',
    );
...

tettoffensive avatar Dec 22 '20 03:12 tettoffensive

First of, apologies for the very delayed response to this - this repo was unmaintained for a bit, but we are trying to bring it back to life. It looks like the root cause here is that we rely on snapshot_ https://github.com/googleapis/nodejs-firestore/blob/master/dev/src/index.ts#L825, which is private. I'm going to chat with my team about how we should fix this, and try to rework this to use public methods.

joehan avatar Jul 07 '21 18:07 joehan

Any updates on this issue?

jekozyra avatar Oct 01 '21 21:10 jekozyra

@joehan any news on this issue? Following the officiel doc we need to use the makeDocumentSnapshot.

HugoGresse avatar May 14 '22 13:05 HugoGresse

Maybe @TheIronDev can help as he is the most recent contributors? The issue happens with "firebase-functions-test": "^2.0.2",

HugoGresse avatar May 14 '22 13:05 HugoGresse

I can certainly take a look.

Giving a heads up, it might be a minute while I sort through previous history.

TheIronDev avatar May 14 '22 18:05 TheIronDev

@tettoffensive || @HugoGresse

Do either of you have a repo that can reproduce this? I attempted for a while this morning but was not able to reproduce. Might be due to my node version + installed modules.

TheIronDev avatar May 17 '22 21:05 TheIronDev

@TheIronDev I do not. I reported this a couple years ago. But it seems like snapshot_ is still not an exposed method. So I'm not sure why makeDocumentSnapshot would work for you.

tettoffensive avatar May 17 '22 21:05 tettoffensive

I've made a small repro : https://github.com/HugoGresse/84-fb-functions-makesnapshot-repro BUT, the issue is caused by my stub for firestore... which is 🤦 only a PEBKAC issue

HugoGresse avatar May 18 '22 11:05 HugoGresse

@HugoGresse - It wasn't a PEBKAC issue until recently :)

@tettoffensive -

Digging deeper, it looks like this issue was introduced in https://github.com/googleapis/nodejs-firestore/pull/1570, when a bunch of @internal were added.

However, https://github.com/googleapis/nodejs-firestore/pull/1688 added @private annotations to a handful of the snapshot_ overload signatures.

I believe this makes most of the overloads accessible, with the exception of the first signature that does contain the @internal here

I'll try to open up a cl to change the @internal to @private, stay tuned!

TheIronDev avatar May 18 '22 19:05 TheIronDev

@TheIronDev Good find. I think when I initially reported it I was working with the firebase-admin package, which I'm not even sure has snapshot_. I'll have to dig since I can't really remember if that's the case or not.

tettoffensive avatar May 18 '22 20:05 tettoffensive

https://github.com/googleapis/nodejs-firestore/pull/1728 got merged, which resolves this issue! 🎉

TheIronDev avatar Dec 21 '22 16:12 TheIronDev