@@ -43,6 +43,7 @@ - (void)testGetDocuments {
43
43
// We currently require every document read to also be written.
44
44
// TODO(b/34879758): Fix this check once we drop that requirement.
45
45
XCTAssertNotNil (error);
46
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
46
47
[expectation fulfill ];
47
48
}];
48
49
[self awaitExpectations ];
@@ -115,9 +116,7 @@ - (void)testGetNonexistentDocumentThenFailPatch {
115
116
XCTAssertNil (result);
116
117
XCTAssertNotNil (error);
117
118
XCTAssertEqualObjects (error.domain , FIRFirestoreErrorDomain);
118
- // TODO(dimond): This is probably the wrong error code, but it's what we use today. We
119
- // should update the code once the underlying error was fixed.
120
- XCTAssertEqual (error.code , FIRFirestoreErrorCodeFailedPrecondition);
119
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
121
120
[expectation fulfill ];
122
121
}];
123
122
[self awaitExpectations ];
@@ -143,9 +142,7 @@ - (void)testDeleteDocumentAndPatch {
143
142
XCTAssertNil (result);
144
143
XCTAssertNotNil (error);
145
144
XCTAssertEqualObjects (error.domain , FIRFirestoreErrorDomain);
146
- // TODO(dimond): This is probably the wrong error code, but it's what we use today. We
147
- // should update the code once the underlying error was fixed.
148
- XCTAssertEqual (error.code , FIRFirestoreErrorCodeFailedPrecondition);
145
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
149
146
[expectation fulfill ];
150
147
}];
151
148
[self awaitExpectations ];
@@ -172,9 +169,8 @@ - (void)testDeleteDocumentAndSet {
172
169
XCTAssertNil (result);
173
170
XCTAssertNotNil (error);
174
171
XCTAssertEqualObjects (error.domain , FIRFirestoreErrorDomain);
175
- // TODO(dimond): This is probably the wrong error code, but it's what we use today. We
176
- // should update the code once the underlying error was fixed.
177
- XCTAssertEqual (error.code , FIRFirestoreErrorCodeFailedPrecondition);
172
+ // This is the error surfaced by the backend.
173
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
178
174
[expectation fulfill ];
179
175
}];
180
176
[self awaitExpectations ];
@@ -237,6 +233,8 @@ - (void)testCannotUpdateNonExistentDocument {
237
233
}
238
234
completion: ^(id _Nullable result, NSError *_Nullable error) {
239
235
XCTAssertNotNil (error);
236
+ // This is the error surfaced by the backend.
237
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeNotFound);
240
238
[expectation fulfill ];
241
239
}];
242
240
[self awaitExpectations ];
@@ -373,6 +371,7 @@ - (void)testHandleReadingOneDocAndWritingAnother {
373
371
// XCTAssertNil(error);
374
372
// XCTAssertEqualObjects(@(16), snapshot[@"count"]);
375
373
XCTAssertNotNil (error);
374
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
376
375
[expectation fulfill ];
377
376
}];
378
377
[self awaitExpectations ];
@@ -410,13 +409,49 @@ - (void)testReadingADocTwiceWithDifferentVersions {
410
409
}
411
410
completion: ^(id _Nullable result, NSError *_Nullable error) {
412
411
[expectation fulfill ];
412
+ XCTAssertNotNil (error);
413
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeAborted);
413
414
}];
414
415
[self awaitExpectations ];
415
416
416
417
FIRDocumentSnapshot *snapshot = [self readDocumentForRef: doc];
417
418
XCTAssertEqualObjects (@(1234.0 ), snapshot[@" count" ]);
418
419
}
419
420
421
+ - (void )testReadAndUpdateNonExistentDocumentWithExternalWrite {
422
+ FIRFirestore *firestore = [self firestore ];
423
+ XCTestExpectation *expectation = [self expectationWithDescription: @" transaction" ];
424
+ [firestore
425
+ runTransactionWithBlock: ^id _Nullable (FIRTransaction *transaction, NSError **error) {
426
+ // Get and update a document that doesn't exist so that the transaction fails.
427
+ FIRDocumentReference *doc =
428
+ [[firestore collectionWithPath: @" nonexistent" ] documentWithAutoID ];
429
+ [transaction getDocument: doc error: error];
430
+ XCTAssertNil (*error);
431
+ // Do a write outside of the transaction.
432
+ dispatch_semaphore_t writeSemaphore = dispatch_semaphore_create (0 );
433
+ [doc setData: @{
434
+ @" count" : @(1234 )
435
+ }
436
+ completion: ^(NSError *_Nullable error) {
437
+ dispatch_semaphore_signal (writeSemaphore);
438
+ }];
439
+ // We can block on it, because transactions run on a background queue.
440
+ dispatch_semaphore_wait (writeSemaphore, DISPATCH_TIME_FOREVER);
441
+ // Now try to update the other doc from within the transaction.
442
+ // This should fail, because the document didn't exist at the
443
+ // start of the transaction.
444
+ [transaction updateData: @{@" count" : @(16 )} forDocument: doc];
445
+ return nil ;
446
+ }
447
+ completion: ^(id _Nullable result, NSError *_Nullable error) {
448
+ [expectation fulfill ];
449
+ XCTAssertNotNil (error);
450
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
451
+ }];
452
+ [self awaitExpectations ];
453
+ }
454
+
420
455
- (void )testCannotHaveAGetWithoutMutations {
421
456
FIRFirestore *firestore = [self firestore ];
422
457
FIRDocumentReference *doc = [[firestore collectionWithPath: @" foo" ] documentWithAutoID ];
@@ -433,6 +468,7 @@ - (void)testCannotHaveAGetWithoutMutations {
433
468
// We currently require every document read to also be written.
434
469
// TODO(b/34879758): Fix this check once we drop that requirement.
435
470
XCTAssertNotNil (error);
471
+ XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
436
472
[expectation fulfill ];
437
473
}];
438
474
[self awaitExpectations ];
0 commit comments