Skip to content

Commit

Permalink
Check paths in Query.isEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
iwikal committed Oct 16, 2019
1 parent 7caeab3 commit 0a3913e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/modules/firestore/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ export default class Query {
return false;
}

if (
this._referencePath.relativeName !==
otherQuery._referencePath.relativeName
) {
return false;
}

if (this._fieldFilters.length !== otherQuery._fieldFilters.length) {
return false;
}
Expand Down
27 changes: 26 additions & 1 deletion tests/e2e/firestore/query.e2e.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('firestore()', () => {
describe('Query', () => {
describe('isEqual()', () => {
it(`returns true if two Queries have the same .where and .orderBy calls`, () => {
it(`returns true if two Queries for the same collection have the same .where and .orderBy calls`, () => {
const ref1 = firebase
.firestore()
.collection('foo')
Expand All @@ -17,6 +17,31 @@ describe('firestore()', () => {
should.equal(ref1.isEqual(ref2), true);
});

it(`returns false if the two Queries are for different collections`, () => {
const ref1 = firebase
.firestore()
.collection('foo')
.where('bar', '==', true);
const ref2 = firebase
.firestore()
.collection('baz')
.where('bar', '==', true);
should.equal(ref1.isEqual(ref2), false);
});

it(`returns false if two Queries have different number of .where calls`, () => {
const ref1 = firebase
.firestore()
.collection('foo')
.where('bar', '==', true);
const ref2 = firebase
.firestore()
.collection('foo')
.where('bar', '==', true)
.where('baz', '!=', false);
should.equal(ref1.isEqual(ref2), false);
});

it(`returns false if two Queries have different number of .where calls`, () => {
const ref1 = firebase
.firestore()
Expand Down

0 comments on commit 0a3913e

Please sign in to comment.