aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Integration
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/Example/Tests/Integration')
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m79
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRListenerRegistrationTests.m33
-rw-r--r--Firestore/Example/Tests/Integration/FSTDatastoreTests.m5
3 files changed, 116 insertions, 1 deletions
diff --git a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m
index 6a727ad..d22552a 100644
--- a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m
+++ b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m
@@ -18,6 +18,8 @@
#import <XCTest/XCTest.h>
+#import "Core/FSTFirestoreClient.h"
+#import "FIRFirestore+Internal.h"
#import "FSTIntegrationTestCase.h"
@interface FIRDatabaseTests : FSTIntegrationTestCase
@@ -766,4 +768,81 @@
XCTAssertEqualObjects([self.db documentWithPath:@"foo/bar/baz/qux"].documentID, @"qux");
}
+- (void)testCanQueueWritesWhileOffline {
+ XCTestExpectation *writeEpectation = [self expectationWithDescription:@"successfull write"];
+ XCTestExpectation *networkExpectation = [self expectationWithDescription:@"enable network"];
+
+ FIRDocumentReference *doc = [self documentRef];
+ FIRFirestore *firestore = doc.firestore;
+ NSDictionary<NSString *, id> *data = @{@"a" : @"b"};
+
+ [firestore.client disableNetworkWithCompletion:^(NSError *error) {
+ XCTAssertNil(error);
+
+ [doc setData:data
+ completion:^(NSError *error) {
+ XCTAssertNil(error);
+ [writeEpectation fulfill];
+ }];
+
+ [firestore.client enableNetworkWithCompletion:^(NSError *error) {
+ XCTAssertNil(error);
+ [networkExpectation fulfill];
+ }];
+ }];
+
+ [self awaitExpectations];
+
+ XCTestExpectation *getExpectation = [self expectationWithDescription:@"successfull get"];
+ [doc getDocumentWithCompletion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(snapshot.data, data);
+ XCTAssertFalse(snapshot.metadata.isFromCache);
+
+ [getExpectation fulfill];
+ }];
+
+ [self awaitExpectations];
+}
+
+- (void)testCantGetDocumentsWhileOffline {
+ FIRDocumentReference *doc = [self documentRef];
+ FIRFirestore *firestore = doc.firestore;
+ NSDictionary<NSString *, id> *data = @{@"a" : @"b"};
+
+ XCTestExpectation *onlineExpectation = [self expectationWithDescription:@"online read"];
+ XCTestExpectation *networkExpectation = [self expectationWithDescription:@"network online"];
+
+ __weak FIRDocumentReference *weakDoc = doc;
+
+ [firestore.client disableNetworkWithCompletion:^(NSError *error) {
+ XCTAssertNil(error);
+ [doc setData:data
+ completion:^(NSError *_Nullable error) {
+ XCTAssertNil(error);
+
+ [weakDoc getDocumentWithCompletion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
+ XCTAssertNil(error);
+
+ // Verify that we are not reading from cache.
+ XCTAssertFalse(snapshot.metadata.isFromCache);
+ [onlineExpectation fulfill];
+ }];
+ }];
+
+ [doc getDocumentWithCompletion:^(FIRDocumentSnapshot *snapshot, NSError *error) {
+ XCTAssertNil(error);
+
+ // Verify that we are reading from cache.
+ XCTAssertTrue(snapshot.metadata.fromCache);
+ XCTAssertEqualObjects(snapshot.data, data);
+ [firestore.client enableNetworkWithCompletion:^(NSError *error) {
+ [networkExpectation fulfill];
+ }];
+ }];
+ }];
+
+ [self awaitExpectations];
+}
+
@end
diff --git a/Firestore/Example/Tests/Integration/API/FIRListenerRegistrationTests.m b/Firestore/Example/Tests/Integration/API/FIRListenerRegistrationTests.m
index 19771ff..5824314 100644
--- a/Firestore/Example/Tests/Integration/API/FIRListenerRegistrationTests.m
+++ b/Firestore/Example/Tests/Integration/API/FIRListenerRegistrationTests.m
@@ -18,6 +18,8 @@
#import <XCTest/XCTest.h>
+#import "Core/FSTFirestoreClient.h"
+#import "FIRFirestore+Internal.h"
#import "FSTIntegrationTestCase.h"
@interface FIRListenerRegistrationTests : FSTIntegrationTestCase
@@ -126,4 +128,35 @@
[two remove];
}
+- (void)testWatchSurvivesNetworkDisconnect {
+ XCTestExpectation *testExpectiation =
+ [self expectationWithDescription:@"testWatchSurvivesNetworkDisconnect"];
+
+ FIRCollectionReference *collectionRef = [self collectionRef];
+ FIRDocumentReference *docRef = [collectionRef documentWithAutoID];
+
+ FIRFirestore *firestore = collectionRef.firestore;
+
+ FIRQueryListenOptions *options = [[[FIRQueryListenOptions options]
+ includeDocumentMetadataChanges:YES] includeQueryMetadataChanges:YES];
+
+ [collectionRef addSnapshotListenerWithOptions:options
+ listener:^(FIRQuerySnapshot *snapshot, NSError *error) {
+ XCTAssertNil(error);
+ if (!snapshot.empty && !snapshot.metadata.fromCache) {
+ [testExpectiation fulfill];
+ }
+ }];
+
+ [firestore.client disableNetworkWithCompletion:^(NSError *error) {
+ XCTAssertNil(error);
+ [docRef setData:@{@"foo" : @"bar"}];
+ [firestore.client enableNetworkWithCompletion:^(NSError *error) {
+ XCTAssertNil(error);
+ }];
+ }];
+
+ [self awaitExpectations];
+}
+
@end
diff --git a/Firestore/Example/Tests/Integration/FSTDatastoreTests.m b/Firestore/Example/Tests/Integration/FSTDatastoreTests.m
index bab8f44..54ab66b 100644
--- a/Firestore/Example/Tests/Integration/FSTDatastoreTests.m
+++ b/Firestore/Example/Tests/Integration/FSTDatastoreTests.m
@@ -174,7 +174,10 @@ NS_ASSUME_NONNULL_BEGIN
credentials:_credentials];
_remoteStore = [FSTRemoteStore remoteStoreWithLocalStore:_localStore datastore:_datastore];
- [_remoteStore start];
+
+ [_testWorkerQueue dispatchAsync:^() {
+ [_remoteStore start];
+ }];
}
- (void)tearDown {