Skip to content

Commit

Permalink
fix(firestore): remove assertion for arrayContainsAny & whereIn q…
Browse files Browse the repository at this point in the history
…uery combined (#11342)

* fix(firestore): remove assertion for arrayContainsAny & whereIn

* test(firestore): for arrayContainsAny & whereIn combined

* test(firestore): rm arrayContainsAny & whereIn assertion tests
  • Loading branch information
russellwheatley committed Jul 21, 2023
1 parent 9be203f commit 199e1fc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
Expand Up @@ -2391,6 +2391,42 @@ void runQueryTests() {
expect(results.docs[1].id, equals('doc3'));
});

testWidgets('"whereIn" query combined with "arrayContainsAny"',
(widgetTester) async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('where-filter-arraycontainsany-in-combined');
await Future.wait([
collection.doc('doc1').set({
'value': [1, 2, 3],
'prop': 'foo',
}),
collection.doc('doc2').set({
'value': [2, 4, 5],
'prop': 'bar',
}),
collection.doc('doc3').set({
'value': [6, 7, 8],
'prop': 'basalt',
}),
]);

final results = await collection
.where(
'value',
arrayContainsAny: [1, 7],
)
.where(
'prop',
whereIn: ['foo', 'basalt'],
)
.orderBy('prop')
.get();

expect(results.docs.length, equals(2));
expect(results.docs[0].id, equals('doc3'));
expect(results.docs[1].id, equals('doc1'));
});

testWidgets('isEqualTo filter', (_) async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('where-filter-isequalto');
Expand Down
7 changes: 0 additions & 7 deletions packages/cloud_firestore/cloud_firestore/lib/src/query.dart
Expand Up @@ -792,13 +792,6 @@ class _JsonQuery implements Query<Map<String, dynamic>> {
hasArrayContainsAny = true;
}

if (operator == 'array-contains-any' || operator == 'in') {
assert(
!(hasIn && hasArrayContainsAny),
"You cannot use 'in' filters with 'array-contains-any' filters.",
);
}

if (operator == 'array-contains' || operator == 'array-contains-any') {
assert(
!(hasArrayContains && hasArrayContainsAny),
Expand Down
14 changes: 0 additions & 14 deletions packages/cloud_firestore/cloud_firestore/test/query_test.dart
Expand Up @@ -191,20 +191,6 @@ void main() {
),
throwsAssertionError,
);
expect(
() => query!.where('foo', arrayContainsAny: [2, 3]).where(
'foo',
whereIn: [2, 3],
),
throwsAssertionError,
);
expect(
() => query!.where('foo', whereIn: [2, 3]).where(
'foo',
arrayContainsAny: [2, 3],
),
throwsAssertionError,
);
expect(
() => query!
.where('foo', whereIn: [2, 3])
Expand Down

0 comments on commit 199e1fc

Please sign in to comment.