aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Integration/API
diff options
context:
space:
mode:
authorGravatar Sebastian Schmidt <mrschmidt@google.com>2017-10-11 04:51:05 +0200
committerGravatar GitHub <noreply@github.com>2017-10-11 04:51:05 +0200
commitae171bb226246e8b485f688e6ddf2dd8dc9fa9be (patch)
treeb28eb368904608f8a466b0ced9a4606e193c7efe /Firestore/Example/Tests/Integration/API
parent73d5cffffd3c5cc3f1f9b92db1bcbc26739cf1bc (diff)
Adding goOnline/goOffline to the RemoteStore (#347)
Diffstat (limited to 'Firestore/Example/Tests/Integration/API')
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m79
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRListenerRegistrationTests.m33
2 files changed, 112 insertions, 0 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