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

Firestore Unit Testing #35

Open
akapur99 opened this issue Sep 22, 2020 · 0 comments
Open

Firestore Unit Testing #35

akapur99 opened this issue Sep 22, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@akapur99
Copy link
Collaborator

akapur99 commented Sep 22, 2020

What We Want To Do

Implement (in-memory) unit tests for calls to Firebase firestore which actually test functionality (similar to SQLite)

What are We Currently Doing

We are currently jest mocking the firestore methods with empty mock functions, without really testing functionality. We need to expand on this to:

  • 1 - Add get() method to the mocks
  • 2 - Add unit tests to at least see that the methods are getting called with the correct parameters/data

Methods Tried in the Past

Firebase Emulation

This would be ideal BUT not ideal for in-memory local unit tests as it requires a separate process (not in-memory). We should might want to be setting this up in the future though, alongside BDD/integration testing

Firebase Functions Test

  • firebase-functions-test is also not ideal as it is built specifically for Cloud functions which we are not using (but can switch to)
  • Furthermore, Firebase reccomends using these for online tests, and dissuades from siloed offline testing:

Using offline mode is generally not recommended if you have Cloud Firestore or Realtime Database functions, since it greatly increases the complexity of your test code.

firebase-mock

  • Ensure you are using the fork by dmurvihill not the main repo (original repo owner is not maintaining it)
  • Seems ideal for our purposes however when listening for doc changes triggers - it doesn't have the latest querySnapshot.docChanges() method. It might still be possible to use this package but would require moving to a firebase-functions implementation of triggers/listeners for Firebase doc changes
  • Have also made an issue for the above in the repo - worth revisiting if it gets fixed.
  • Checkout branch firebaseMocking(https://github.com/mojaloop/pisp-demo-server/tree/firebaseMocking) for attempted implementation

firebase-mock + Basic Jest Mocking

ts-mock-firebase

  • Both @eoln and I were unable to install or use this package.

firebase-nightlight

  • Too old and doesn't support enough features
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants