sbatson5 / firestore-jest-mock

Jest Helper library for mocking Cloud Firestore
https://www.npmjs.com/package/firestore-jest-mock
177 stars 57 forks source link

firestore and auth mocks not complete on firebase-admin #159

Open geraldosalazar16 opened 1 year ago

geraldosalazar16 commented 1 year ago

Summary

It looks like the mocks for firestore and auth (in tyhe firebase-admin) are outdated

Brief explanation of the feature. When trying to mock firestore I got errors about recursiveDelete (in firestore) and getUserByEmail (in auth) not being functions. I added recursiveDelete on https://github.com/Upstatement/firestore-jest-mock/blob/master/mocks/firestore.js and getUserByEmail on https://github.com/Upstatement/firestore-jest-mock/blob/master/mocks/auth.js and my tests started passing

Basic example

getUserByEmail() { return Promise.resolve(mockGetUser(...arguments) || {}); }

recursiveDelete() { return Promise.resolve(); } If the proposal involves a new or changed API, include a basic code example. Omit this section if it's not applicable.

Motivation

Why are we doing this? What use cases does it support? What is the expected outcome? My workaround so far has being ` import { FakeFirestore } from 'firestore-jest-mock/mocks/firestore'; Object.setPrototypeOf(FakeFirestore.prototype, { ...Object.getPrototypeOf(FakeFirestore.prototype), recursiveDelete: jest.fn().mockResolvedValue('ok'), });

import { FakeAuth } from 'firestore-jest-mock/mocks/auth'; Object.setPrototypeOf(FakeAuth.prototype, { ...Object.getPrototypeOf(FakeAuth.prototype), getUserByEmail: jest .fn() .mockResolvedValue({ id: 'abc123', name: 'Homer Simpson' }), }); `

sbatson5 commented 1 year ago

Thanks for the update. Do want to open a PR to add these functions into the mock file? I'd be happy to merge them 👍