diff --git a/packages/firestore/src/core/query.ts b/packages/firestore/src/core/query.ts index cffa3345995..3827abdf2a8 100644 --- a/packages/firestore/src/core/query.ts +++ b/packages/firestore/src/core/query.ts @@ -789,7 +789,9 @@ export class Bound { for (let i = 0; i < this.position.length; i++) { const thisPosition = this.position[i]; const otherPosition = other.position[i]; - return thisPosition.isEqual(otherPosition); + if (!thisPosition.isEqual(otherPosition)) { + return false; + } } return true; } diff --git a/packages/firestore/test/unit/core/query.test.ts b/packages/firestore/test/unit/core/query.test.ts index 8b83a5b9baa..3510b59b569 100644 --- a/packages/firestore/test/unit/core/query.test.ts +++ b/packages/firestore/test/unit/core/query.test.ts @@ -16,7 +16,7 @@ */ import { expect } from 'chai'; -import { Query } from '../../../src/core/query'; +import { Bound, Query } from '../../../src/core/query'; import { DOCUMENT_KEY_NAME, ResourcePath } from '../../../src/model/path'; import { addEqualityMatcher } from '../../util/equality_matcher'; import { @@ -27,9 +27,37 @@ import { filter, orderBy, path, - ref + ref, + wrap } from '../../util/helpers'; +describe('Bound', () => { + function makeBound(values: unknown[], before: boolean): Bound { + return new Bound(values.map(el => wrap(el)), before); + } + + it('implements isEqual', () => { + let bound = makeBound([1, 2], true); + expect(bound.isEqual(makeBound([1, 2], true))).to.be.true; + + // Mismatch values + expect(bound.isEqual(makeBound([2, 2], true))).to.be.false; + expect(bound.isEqual(makeBound([1, 3], true))).to.be.false; + + // Mismatch before + expect(bound.isEqual(makeBound([1, 2], false))).to.be.false; + + // Unequal lengths + expect(bound.isEqual(makeBound([], true))).to.be.false; + expect(bound.isEqual(makeBound([1], true))).to.be.false; + expect(bound.isEqual(makeBound([1, 2, 3], true))).to.be.false; + + // Zero length + bound = makeBound([], false); + expect(bound.isEqual(makeBound([], false))).to.be.true; + }); +}); + describe('Query', () => { addEqualityMatcher();