sbatson5 / firestore-jest-mock

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

feat(query): implement more query methods #173

Open FrederikBanke opened 1 year ago

FrederikBanke commented 1 year ago

Description

I have implemented 4 methods related to the Query class.

They should behave more like the actual Firestore methods.

Do note, that I have not taken simulateQueryFilters into consideration, but it should be a quick fix, if the new functions should only run when simulateQueryFilters is set to true.

Limitations

In functions where values needs to be compared, only numbers, strings and timestamps are compared.

How to test

I have added tests in query.test.js, that test Query.limit(), Query.orderBy(), Query.startAt() and Query.startAfter().

sbatson5 commented 1 year ago

I'm gonna set some time aside to review this soon. But as a note, I am planning on releasing a breaking version (1.0.0) where I think I'm going to make simulateQueryFilters true by default. So the param would be disabling. My only worry is that if we don't have perfect feature parody, people may end up thinking their tests are wrong even though it's just our mock that isn't querying exactly right (which isn't important for writing tests imo).

FrederikBanke commented 1 year ago

I understand not merging, if it does not align with the purpose of the project. The reason I made the changes myself, was because I did need the queries to simulate for my own tests.

I just created the pull request in case it was of use to others.

I also understand that it can create my problems, if it doesn't work 1:1 with the real queries.