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
Feature/fix aggregate issue with converted queries #291
Feature/fix aggregate issue with converted queries #291
Conversation
@@ -0,0 +1,16 @@ | |||
import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_interface.dart'; | |||
|
|||
extension AggregateTypeExtension on AggregateType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fancy! 👍
lib/src/fake_aggregate_query.dart
Outdated
@@ -28,10 +31,18 @@ class FakeAggregateQuery implements AggregateQuery { | |||
@override | |||
AggregateQuery count() => _query.count(); | |||
|
|||
Map<String, dynamic> _getRawDocDataMap(QueryDocumentSnapshot<Object?> s) { | |||
if (s is MockQueryDocumentSnapshot && s.snapshot is MockDocumentSnapshot) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use an assert statement like you did in the other PR? flutter test
does fail if the assert fails. If something does fails for unexpected reasons, let it fail so we can fix it properly next time. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it's because I want to check the type with the is
operator so that we can use the instance method without casting it again.
Let me think and revise it. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after using DocumentSnapshot.get
we don't need this method anymore, haha. Thank you!
lib/src/fake_aggregate_query.dart
Outdated
AggregateQuerySnapshotPlatform _getAggregateQuerySnapshotPlatform({ | ||
required QuerySnapshot<Object?> snapshot, | ||
}) { | ||
final dataMaps = snapshot.docs.map((e) => e.data() as Map<String, dynamic>); | ||
final dataMaps = snapshot.docs.map((s) => _getRawDocDataMap(s)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered using DocumentSnapshot.get
? Then you don't need to expose the internal map. It's better to use the public API whenever possible.
You would replace
final value = dataMap[field.field];
by
final value = documentSnapshot.get(field.field);
It also has the added benefit to make the loop down there clearer. Instead of this:
for (final dataMap in dataMaps) {
for (final field in fields) {
you could write:
for (final field in fields) {
for (final documentSnapshot in documentSnapshots) {
Also would you mind renaming valueMap
into something more meaningful like aggregateValues
? Since you already use the variable name value
when referring to a document value, value
and valueMap
was a bit confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
@atn832 Thanks for the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @ming-chu !
I published your fix to https://pub.dev/packages/fake_cloud_firestore/changelog#247. I also switched to Dart 3 and used pattern matching to rewrite https://dart.dev/language/patterns#switch-statements-and-expressions |
This PR has fixed the aggregate query problem on converted queries.
#290 (comment)
The error log would be like: