Skip to content

Commit

Permalink
fix(firestore): supports Iterable in queries instead of List
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone committed Feb 10, 2023
1 parent cdcfb45 commit 97a692f
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,69 @@ void runQueryTests() {
});
});

test('returns with in filter using Iterable', () async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('where-in-iterable');

await Future.wait([
collection.doc('doc1').set({
'status': 'Ordered',
}),
collection.doc('doc2').set({
'status': 'Ready to Ship',
}),
collection.doc('doc3').set({
'status': 'Ready to Ship',
}),
collection.doc('doc4').set({
'status': 'Incomplete',
}),
]);

QuerySnapshot<Map<String, dynamic>> snapshot = await collection
.where(
'status',
// To force the list to be an iterable
whereIn: ['Ready to Ship', 'Ordered'].map((e) => e),
)
.get();

expect(snapshot.docs.length, equals(3));
snapshot.docs.forEach((doc) {
String status = doc.data()['status'];
expect(status == 'Ready to Ship' || status == 'Ordered', isTrue);
});
});

test('returns with in filter using Set', () async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('where-in');

await Future.wait([
collection.doc('doc1').set({
'status': 'Ordered',
}),
collection.doc('doc2').set({
'status': 'Ready to Ship',
}),
collection.doc('doc3').set({
'status': 'Ready to Ship',
}),
collection.doc('doc4').set({
'status': 'Incomplete',
}),
]);

QuerySnapshot<Map<String, dynamic>> snapshot = await collection
.where('status', whereIn: {'Ready to Ship', 'Ordered'}).get();

expect(snapshot.docs.length, equals(3));
snapshot.docs.forEach((doc) {
String status = doc.data()['status'];
expect(status == 'Ready to Ship' || status == 'Ordered', isTrue);
});
});

test('returns with in filter', () async {
CollectionReference<Map<String, dynamic>> collection =
await initializeTest('where-in');
Expand Down

0 comments on commit 97a692f

Please sign in to comment.