Skip to content

Fix the implementation of Bound.isEqual #1893

New issue

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

Merged
merged 1 commit into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/firestore/src/core/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
32 changes: 30 additions & 2 deletions packages/firestore/test/unit/core/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();

Expand Down