Visitar URL original
fix(firestore, web): update Timestamp handling in jsify and EncodeUti… · firebase/flutterfire@9783a44 · GitHub
Skip to content

Commit 9783a44

Browse files
authored
fix(firestore, web): update Timestamp handling in jsify and EncodeUtility (#18264)
* fix(firestore): update Timestamp handling in jsify and EncodeUtility * chore: refactor Timestamp handling in jsify and add tests for EncodeUtility * chore: add js_interop import to timestamp_cursor_encoding_test.dart * test: add test for startAfterDocument() to ensure Timestamp cursor precision is preserved * fix(tests): skip query test on non-web platforms and remove obsolete timestamp_cursor_encoding_test * fix formating
1 parent 94f793d commit 9783a44

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,33 @@ void runQueryTests() {
10231023
expect(snapshot.docs[1].id, equals('doc4'));
10241024
});
10251025

1026+
test(
1027+
'startAfterDocument() preserves Timestamp cursor precision',
1028+
() async {
1029+
CollectionReference<Map<String, dynamic>> collection =
1030+
await initializeTest('startAfter-document-timestamp-precision');
1031+
await collection.doc('doc1').set({
1032+
'createdAt': Timestamp(1, 123456789),
1033+
});
1034+
1035+
Query<Map<String, dynamic>> baseQuery =
1036+
collection.orderBy('createdAt');
1037+
QuerySnapshot<Map<String, dynamic>> firstPage =
1038+
await baseQuery.limit(50).get();
1039+
1040+
expect(firstPage.docs.length, equals(1));
1041+
expect(firstPage.docs.first.id, equals('doc1'));
1042+
1043+
QuerySnapshot<Map<String, dynamic>> nextPage = await baseQuery
1044+
.startAfterDocument(firstPage.docs.last)
1045+
.limit(50)
1046+
.get();
1047+
1048+
expect(nextPage.docs, isEmpty);
1049+
},
1050+
skip: !kIsWeb,
1051+
);
1052+
10261053
testWidgets(
10271054
'throws exception without orderBy() on field used for inequality query',
10281055
(_) async {

‎packages/cloud_firestore/cloud_firestore_web/lib/src/utils/encode_utility.dart‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ class EncodeUtility {
120120
} else if (value == FieldPath.documentId) {
121121
return firestore_interop.documentId();
122122
} else if (value is Timestamp) {
123-
return value.toDate();
123+
return firestore_interop.TimestampJsImpl(
124+
value.seconds.toJS,
125+
value.nanoseconds.toJS,
126+
);
124127
} else if (value is GeoPoint) {
125128
return firestore_interop.GeoPointJsImpl(
126129
value.latitude.toJS, value.longitude.toJS);

0 commit comments

Comments
 (0)