Skip to content

Commit 7a52f75

Browse files
authored
Fix the implementation of Bound.isEqual (#1893)
1 parent ae2698f commit 7a52f75

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

packages/firestore/src/core/query.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,9 @@ export class Bound {
789789
for (let i = 0; i < this.position.length; i++) {
790790
const thisPosition = this.position[i];
791791
const otherPosition = other.position[i];
792-
return thisPosition.isEqual(otherPosition);
792+
if (!thisPosition.isEqual(otherPosition)) {
793+
return false;
794+
}
793795
}
794796
return true;
795797
}

packages/firestore/test/unit/core/query.test.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { expect } from 'chai';
19-
import { Query } from '../../../src/core/query';
19+
import { Bound, Query } from '../../../src/core/query';
2020
import { DOCUMENT_KEY_NAME, ResourcePath } from '../../../src/model/path';
2121
import { addEqualityMatcher } from '../../util/equality_matcher';
2222
import {
@@ -27,9 +27,37 @@ import {
2727
filter,
2828
orderBy,
2929
path,
30-
ref
30+
ref,
31+
wrap
3132
} from '../../util/helpers';
3233

34+
describe('Bound', () => {
35+
function makeBound(values: unknown[], before: boolean): Bound {
36+
return new Bound(values.map(el => wrap(el)), before);
37+
}
38+
39+
it('implements isEqual', () => {
40+
let bound = makeBound([1, 2], true);
41+
expect(bound.isEqual(makeBound([1, 2], true))).to.be.true;
42+
43+
// Mismatch values
44+
expect(bound.isEqual(makeBound([2, 2], true))).to.be.false;
45+
expect(bound.isEqual(makeBound([1, 3], true))).to.be.false;
46+
47+
// Mismatch before
48+
expect(bound.isEqual(makeBound([1, 2], false))).to.be.false;
49+
50+
// Unequal lengths
51+
expect(bound.isEqual(makeBound([], true))).to.be.false;
52+
expect(bound.isEqual(makeBound([1], true))).to.be.false;
53+
expect(bound.isEqual(makeBound([1, 2, 3], true))).to.be.false;
54+
55+
// Zero length
56+
bound = makeBound([], false);
57+
expect(bound.isEqual(makeBound([], false))).to.be.true;
58+
});
59+
});
60+
3361
describe('Query', () => {
3462
addEqualityMatcher();
3563

0 commit comments

Comments
 (0)