We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
set
When there are nested collections set does not work as expected.
function fakeFirestore() { return firebaseStub( {database: {}}, {mutable: true}, ).firestore(); } test('Setting collections conflicts', async () => { const firestore = fakeFirestore(); await firestore.doc('teams/teamID/users/userID').set({name: 'User Name'}); await firestore.doc('teams/teamID').set({name: 'Team Name'}); expect((await firestore.doc('teams/teamID').get()).data()).toEqual({ name: 'Team Name', }); expect( (await firestore.doc('teams/teamID/users/userID').get()).data(), ).toEqual({ name: 'User Name', }); });
The problem is that the second set does not propagate the _collections.
_collections
The _collections property should be maintained and a set should not drop sub collections.
The teams/teamID/users/userID doc is lost
teams/teamID/users/userID
v18.16.0
https://github.com/Upstatement/firestore-jest-mock/blob/f2158d050d3c334c049ed49b68c6849f90c0fa56/mocks/firestore.js#L217-L224
// parent should now be an array of documents // Replace existing data, if it's there, or add to the end of the array const oldIndex = parent.findIndex(doc => doc.id === docId); const newIndex = oldIndex >= 0 ? oldIndex : parent.length; const newValue = { ...(merge ? parent[oldIndex] : undefined), ...object, id: docId, }; const oldValue = parent[newIndex]; if (oldValue?._collections) { newValue._collections = oldValue._collections; } parent[newIndex] = newValue;
The above can be written more concise with ... and ?. and ?
...
?.
?
The text was updated successfully, but these errors were encountered:
Just came to the repository to report this error, it's sad to know it's been happening for while
Sorry, something went wrong.
No branches or pull requests
Description
When there are nested collections
set
does not work as expected.Steps to reproduce
The problem is that the second
set
does not propagate the_collections
.Expected result
The
_collections
property should be maintained and a set should not drop sub collections.Actual result
The
teams/teamID/users/userID
doc is lostEnvironment
v18.16.0
Potential fix:
https://github.com/Upstatement/firestore-jest-mock/blob/f2158d050d3c334c049ed49b68c6849f90c0fa56/mocks/firestore.js#L217-L224
The above can be written more concise with
...
and?.
and?
The text was updated successfully, but these errors were encountered: