Skip to content

Commit

Permalink
fix(firestore): cannot use not-in & in filters in the same query (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Feb 9, 2024
1 parent 4d3b578 commit e538338
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/cloud_firestore/cloud_firestore/lib/src/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,19 @@ class _JsonQuery implements Query<Map<String, dynamic>> {
!hasNotEqualTo,
"You cannot use 'not-in' filters with '!=' filters.",
);
assert(
!hasIn,
"You cannot use 'not-in' filters with 'in' filters.",
);
hasNotIn = true;
}

if (operator == 'in') {
assert(!hasIn, "You cannot use 'whereIn' filters more than once.");
assert(
!hasNotIn,
"You cannot use 'in' filters with 'not-in' filters.",
);
hasIn = true;
}

Expand Down
24 changes: 24 additions & 0 deletions packages/cloud_firestore/cloud_firestore/test/query_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ void main() {
.where('foo.bar', isGreaterThan: 1234);
});

test('throw an exception when making query combining `in` & `not-in`',
() {
expect(
() => query!.where('number', whereIn: [1, 2], whereNotIn: [3, 4]),
throwsAssertionError,
);

expect(
() => query!.where('number', whereIn: [1, 2]).where(
'number',
whereNotIn: [3, 4],
),
throwsAssertionError,
);

expect(
() => query!.where('number', whereNotIn: [3, 4]).where(
'number',
whereIn: [1, 2],
),
throwsAssertionError,
);
});

test('throws if inequality is different to first orderBy', () {
expect(
() => query!.where('foo', isGreaterThan: 123).orderBy('bar'),
Expand Down

0 comments on commit e538338

Please sign in to comment.