File tree Expand file tree Collapse file tree 3 files changed +46
-2
lines changed
Example/Tests/Integration/API Expand file tree Collapse file tree 3 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 44- [ fixed] Fixed an internal assertion that was triggered when an update
55 with a ` FieldValue.serverTimestamp() ` and an update with a
66 ` FieldValue.increment() ` were pending for the same document.
7+ - [ fixed] Fixed the ` oldIndex ` and ` newIndex ` values in ` DocumentChange ` to
8+ actually be ` NSNotFound ` when documents are added or removed, respectively
9+ (#3298 ).
710- [ changed] Failed transactions now return the failure from the last attempt,
811 instead of ` ABORTED. `
912
Original file line number Diff line number Diff line change @@ -252,6 +252,35 @@ - (void)testQueriesFireFromCacheWhenOffline {
252252 [registration remove ];
253253}
254254
255+ - (void )testDocumentChangesUseNSNotFound {
256+ NSDictionary *testDocs = @{
257+ @" a" : @{@" foo" : @1 },
258+ };
259+ FIRCollectionReference *collection = [self collectionRefWithDocuments: testDocs];
260+
261+ id <FIRListenerRegistration> registration =
262+ [collection addSnapshotListener: self .eventAccumulator.valueEventHandler];
263+
264+ FIRQuerySnapshot *querySnap = [self .eventAccumulator awaitEventWithName: @" initial event" ];
265+ XCTAssertEqual (querySnap.documentChanges .count , 1 );
266+
267+ FIRDocumentChange *change = querySnap.documentChanges [0 ];
268+ XCTAssertEqual (change.oldIndex , NSNotFound );
269+ XCTAssertEqual (change.newIndex , 0 );
270+
271+ FIRDocumentReference *doc = change.document .reference ;
272+ [self deleteDocumentRef: doc];
273+
274+ querySnap = [self .eventAccumulator awaitEventWithName: @" delete" ];
275+ XCTAssertEqual (querySnap.documentChanges .count , 1 );
276+
277+ change = querySnap.documentChanges [0 ];
278+ XCTAssertEqual (change.oldIndex , 0 );
279+ XCTAssertEqual (change.newIndex , NSNotFound );
280+
281+ [registration remove ];
282+ }
283+
255284- (void )testCanHaveMultipleMutationsWhileOffline {
256285 FIRCollectionReference *col = [self collectionRef ];
257286
Original file line number Diff line number Diff line change 2525
2626NS_ASSUME_NONNULL_BEGIN
2727
28+ namespace {
29+
30+ /* *
31+ * Converts from C++ document change indexes to Objective-C document change
32+ * indexes. Objective-C's NSNotFound is signed NSIntegerMax, not unsigned -1.
33+ */
34+ constexpr NSUInteger MakeIndex (size_t index) {
35+ return index == DocumentChange::npos ? NSNotFound : index;
36+ }
37+
38+ } // namespace
39+
2840@implementation FIRDocumentChange {
2941 DocumentChange _documentChange;
3042}
@@ -66,11 +78,11 @@ - (FIRQueryDocumentSnapshot *)document {
6678}
6779
6880- (NSUInteger )oldIndex {
69- return _documentChange.old_index ();
81+ return MakeIndex ( _documentChange.old_index () );
7082}
7183
7284- (NSUInteger )newIndex {
73- return _documentChange.new_index ();
85+ return MakeIndex ( _documentChange.new_index () );
7486}
7587
7688@end
You can’t perform that action at this time.
0 commit comments