aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example
diff options
context:
space:
mode:
authorGravatar Gil <mcg@google.com>2018-04-14 17:19:06 -0700
committerGravatar GitHub <noreply@github.com>2018-04-14 17:19:06 -0700
commit33b12f6c70729d56c6e6350d435559cec1c44c61 (patch)
tree60d916bb7509f82e8950b887b45f9dd0bf80251a /Firestore/Example
parentfd84cd60aaf52cbe405ff8248665029827d56e97 (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')
-rw-r--r--Firestore/Example/SwiftBuildTest/main.swift14
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm162
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.mm4
-rw-r--r--Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm17
4 files changed, 101 insertions, 96 deletions
diff --git a/Firestore/Example/SwiftBuildTest/main.swift b/Firestore/Example/SwiftBuildTest/main.swift
index 691adf6..555a75b 100644
--- a/Firestore/Example/SwiftBuildTest/main.swift
+++ b/Firestore/Example/SwiftBuildTest/main.swift
@@ -255,6 +255,19 @@ func listenToDocument(at docRef: DocumentReference) {
listener.remove()
}
+func listenToDocumentWithMetadataChanges(at docRef: DocumentReference) {
+ let listener = docRef.addSnapshotListener(includeMetadataChanges: true) { document, error in
+ if let document = document {
+ if document.metadata.hasPendingWrites {
+ print("Has pending writes")
+ }
+ }
+ }
+
+ // Unsubscribe.
+ listener.remove()
+}
+
func listenToDocuments(matching query: Query) {
let listener = query.addSnapshotListener { snap, error in
if let error = error {
@@ -330,7 +343,6 @@ func transactions() {
func types() {
let _: CollectionReference
let _: DocumentChange
- let _: DocumentListenOptions
let _: DocumentReference
let _: DocumentSnapshot
let _: FieldPath
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];