firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

makeDocumentSnapshot: TypeError: firestoreService.snapshot_ is not a function #87

Closed tettoffensive closed 1 year ago

tettoffensive commented 3 years ago

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: 'a@gmail.com',
      },
      '/users/testUser',
    );
...
joehan commented 3 years ago

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.

jekozyra commented 2 years ago

Any updates on this issue?

HugoGresse commented 2 years ago

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

HugoGresse commented 2 years ago

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

TheIronDev commented 2 years ago

I can certainly take a look.

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

TheIronDev commented 2 years ago

@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.

tettoffensive commented 2 years ago

@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.

HugoGresse commented 2 years ago

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

TheIronDev commented 2 years ago

@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!

tettoffensive commented 2 years ago

@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.

TheIronDev commented 1 year ago

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