diff options
author | Gil <mcg@google.com> | 2018-04-14 17:19:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-14 17:19:06 -0700 |
commit | 33b12f6c70729d56c6e6350d435559cec1c44c61 (patch) | |
tree | 60d916bb7509f82e8950b887b45f9dd0bf80251a /Firestore/Example/Tests | |
parent | fd84cd60aaf52cbe405ff8248665029827d56e97 (diff) |
Replace `DocumentListenOptions` with a simple boolean. (#1099)
* Replace `DocumentListenOptions` with a simple boolean.
Instead of calling
`addSnapshotListener(options: DocumentListenOptions.includeMetadataChanges(true))`
call
`addSnapshotListener(includeMetadataChanges:true)`
* Style
Diffstat (limited to 'Firestore/Example/Tests')
3 files changed, 88 insertions, 95 deletions
diff --git a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm index 312c3ff..503d50b 100644 --- a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm @@ -370,32 +370,30 @@ __block XCTestExpectation *dataCompletion; __block int callbacks = 0; - FIRDocumentListenOptions *options = - [[FIRDocumentListenOptions options] includeMetadataChanges:YES]; + id<FIRListenerRegistration> listenerRegistration = [docRef + addSnapshotListenerWithIncludeMetadataChanges:YES + listener:^(FIRDocumentSnapshot *_Nullable doc, + NSError *error) { + callbacks++; - id<FIRListenerRegistration> listenerRegistration = - [docRef addSnapshotListenerWithOptions:options - listener:^(FIRDocumentSnapshot *_Nullable doc, NSError *error) { - callbacks++; - - if (callbacks == 1) { - XCTAssertNotNil(doc); - XCTAssertFalse(doc.exists); - [emptyCompletion fulfill]; + if (callbacks == 1) { + XCTAssertNotNil(doc); + XCTAssertFalse(doc.exists); + [emptyCompletion fulfill]; - } else if (callbacks == 2) { - XCTAssertEqualObjects(doc.data, (@{ @"a" : @1 })); - XCTAssertEqual(doc.metadata.hasPendingWrites, YES); + } else if (callbacks == 2) { + XCTAssertEqualObjects(doc.data, (@{ @"a" : @1 })); + XCTAssertEqual(doc.metadata.hasPendingWrites, YES); - } else if (callbacks == 3) { - XCTAssertEqualObjects(doc.data, (@{ @"a" : @1 })); - XCTAssertEqual(doc.metadata.hasPendingWrites, NO); - [dataCompletion fulfill]; + } else if (callbacks == 3) { + XCTAssertEqualObjects(doc.data, (@{ @"a" : @1 })); + XCTAssertEqual(doc.metadata.hasPendingWrites, NO); + [dataCompletion fulfill]; - } else if (callbacks == 4) { - XCTFail("Should not have received this callback"); - } - }]; + } else if (callbacks == 4) { + XCTFail("Should not have received this callback"); + } + }]; [self awaitExpectations]; dataCompletion = [self expectationWithDescription:@"data snapshot"]; @@ -458,40 +456,38 @@ __block XCTestExpectation *changeCompletion; __block int callbacks = 0; - FIRDocumentListenOptions *options = - [[FIRDocumentListenOptions options] includeMetadataChanges:YES]; + id<FIRListenerRegistration> listenerRegistration = [docRef + addSnapshotListenerWithIncludeMetadataChanges:YES + listener:^(FIRDocumentSnapshot *_Nullable doc, + NSError *error) { + callbacks++; - id<FIRListenerRegistration> listenerRegistration = - [docRef addSnapshotListenerWithOptions:options - listener:^(FIRDocumentSnapshot *_Nullable doc, NSError *error) { - callbacks++; - - if (callbacks == 1) { - XCTAssertEqualObjects(doc.data, initialData); - XCTAssertEqual(doc.metadata.hasPendingWrites, NO); - XCTAssertEqual(doc.metadata.isFromCache, YES); - - } else if (callbacks == 2) { - XCTAssertEqualObjects(doc.data, initialData); - XCTAssertEqual(doc.metadata.hasPendingWrites, NO); - XCTAssertEqual(doc.metadata.isFromCache, NO); - [initialCompletion fulfill]; - - } else if (callbacks == 3) { - XCTAssertEqualObjects(doc.data, changedData); - XCTAssertEqual(doc.metadata.hasPendingWrites, YES); - XCTAssertEqual(doc.metadata.isFromCache, NO); - - } else if (callbacks == 4) { - XCTAssertEqualObjects(doc.data, changedData); - XCTAssertEqual(doc.metadata.hasPendingWrites, NO); - XCTAssertEqual(doc.metadata.isFromCache, NO); - [changeCompletion fulfill]; - - } else if (callbacks == 5) { - XCTFail("Should not have received this callback"); - } - }]; + if (callbacks == 1) { + XCTAssertEqualObjects(doc.data, initialData); + XCTAssertEqual(doc.metadata.hasPendingWrites, NO); + XCTAssertEqual(doc.metadata.isFromCache, YES); + + } else if (callbacks == 2) { + XCTAssertEqualObjects(doc.data, initialData); + XCTAssertEqual(doc.metadata.hasPendingWrites, NO); + XCTAssertEqual(doc.metadata.isFromCache, NO); + [initialCompletion fulfill]; + + } else if (callbacks == 3) { + XCTAssertEqualObjects(doc.data, changedData); + XCTAssertEqual(doc.metadata.hasPendingWrites, YES); + XCTAssertEqual(doc.metadata.isFromCache, NO); + + } else if (callbacks == 4) { + XCTAssertEqualObjects(doc.data, changedData); + XCTAssertEqual(doc.metadata.hasPendingWrites, NO); + XCTAssertEqual(doc.metadata.isFromCache, NO); + [changeCompletion fulfill]; + + } else if (callbacks == 5) { + XCTFail("Should not have received this callback"); + } + }]; [self awaitExpectations]; changeCompletion = [self expectationWithDescription:@"listen for changed data"]; @@ -548,39 +544,37 @@ [self writeDocumentRef:docRef data:initialData]; - FIRDocumentListenOptions *options = - [[FIRDocumentListenOptions options] includeMetadataChanges:YES]; - XCTestExpectation *initialCompletion = [self expectationWithDescription:@"initial data"]; __block XCTestExpectation *changeCompletion; __block int callbacks = 0; - id<FIRListenerRegistration> listenerRegistration = - [docRef addSnapshotListenerWithOptions:options - listener:^(FIRDocumentSnapshot *_Nullable doc, NSError *error) { - callbacks++; - - if (callbacks == 1) { - XCTAssertEqualObjects(doc.data, initialData); - XCTAssertEqual(doc.metadata.hasPendingWrites, NO); - XCTAssertEqual(doc.metadata.isFromCache, YES); - - } else if (callbacks == 2) { - XCTAssertEqualObjects(doc.data, initialData); - XCTAssertEqual(doc.metadata.hasPendingWrites, NO); - XCTAssertEqual(doc.metadata.isFromCache, NO); - [initialCompletion fulfill]; - - } else if (callbacks == 3) { - XCTAssertFalse(doc.exists); - XCTAssertEqual(doc.metadata.hasPendingWrites, NO); - XCTAssertEqual(doc.metadata.isFromCache, NO); - [changeCompletion fulfill]; - - } else if (callbacks == 4) { - XCTFail("Should not have received this callback"); - } - }]; + id<FIRListenerRegistration> listenerRegistration = [docRef + addSnapshotListenerWithIncludeMetadataChanges:YES + listener:^(FIRDocumentSnapshot *_Nullable doc, + NSError *error) { + callbacks++; + + if (callbacks == 1) { + XCTAssertEqualObjects(doc.data, initialData); + XCTAssertEqual(doc.metadata.hasPendingWrites, NO); + XCTAssertEqual(doc.metadata.isFromCache, YES); + + } else if (callbacks == 2) { + XCTAssertEqualObjects(doc.data, initialData); + XCTAssertEqual(doc.metadata.hasPendingWrites, NO); + XCTAssertEqual(doc.metadata.isFromCache, NO); + [initialCompletion fulfill]; + + } else if (callbacks == 3) { + XCTAssertFalse(doc.exists); + XCTAssertEqual(doc.metadata.hasPendingWrites, NO); + XCTAssertEqual(doc.metadata.isFromCache, NO); + [changeCompletion fulfill]; + + } else if (callbacks == 4) { + XCTFail("Should not have received this callback"); + } + }]; [self awaitExpectations]; changeCompletion = [self expectationWithDescription:@"listen for changed data"]; diff --git a/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm b/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm index 9a2fef1..b1d6738 100644 --- a/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm @@ -248,9 +248,7 @@ - (void)testCanWriteTheSameDocumentMultipleTimes { FIRDocumentReference *doc = [self documentRef]; FSTEventAccumulator *accumulator = [FSTEventAccumulator accumulatorForTest:self]; - [doc - addSnapshotListenerWithOptions:[[FIRDocumentListenOptions options] includeMetadataChanges:YES] - listener:accumulator.valueEventHandler]; + [doc addSnapshotListenerWithIncludeMetadataChanges:YES listener:accumulator.valueEventHandler]; FIRDocumentSnapshot *initialSnap = [accumulator awaitEventWithName:@"initial event"]; XCTAssertFalse(initialSnap.exists); diff --git a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm index 79163da..2b1f9d0 100644 --- a/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm +++ b/Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm @@ -245,14 +245,15 @@ NS_ASSUME_NONNULL_BEGIN XCTestExpectation *expectation = [self expectationWithDescription:@"listener"]; id<FIRListenerRegistration> listener = [ref - addSnapshotListenerWithOptions:[[FIRDocumentListenOptions options] includeMetadataChanges:YES] - listener:^(FIRDocumentSnapshot *snapshot, NSError *error) { - XCTAssertNil(error); - if (!requireOnline || !snapshot.metadata.fromCache) { - result = snapshot; - [expectation fulfill]; - } - }]; + addSnapshotListenerWithIncludeMetadataChanges:YES + listener:^(FIRDocumentSnapshot *snapshot, + NSError *error) { + XCTAssertNil(error); + if (!requireOnline || !snapshot.metadata.fromCache) { + result = snapshot; + [expectation fulfill]; + } + }]; [self awaitExpectations]; [listener remove]; |