diff options
author | Sebastian Schmidt <mrschmidt@google.com> | 2017-10-03 15:54:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-03 15:54:47 -0700 |
commit | ce2191c04c8640a8ba3fd6445d061a53d3b8070e (patch) | |
tree | 5cb680491d0ee3e2de983477a1bde99a4139446b | |
parent | 4b1b3d62d8f72a19e0359642872edd3393451f47 (diff) |
Adding test for merge with server timestamps (#329)
-rw-r--r-- | Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m index d5558cc..ebfd826 100644 --- a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m +++ b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m @@ -119,7 +119,7 @@ @"desc" : @"Description", @"owner.data" : @{@"name" : @"Jonny", @"email" : @"abc@xyz.com"} }; - NSDictionary<NSString *, id> *updateData = + NSDictionary<NSString *, id> *mergeData = @{ @"updated" : @YES, @"owner.data" : @{@"name" : @"Sebastian"} }; NSDictionary<NSString *, id> *finalData = @{ @@ -133,7 +133,7 @@ XCTestExpectation *completed = [self expectationWithDescription:@"testCanMergeDataWithAnExistingDocumentUsingSet"]; - [doc setData:updateData + [doc setData:mergeData options:[FIRSetOptions merge] completion:^(NSError *error) { XCTAssertNil(error); @@ -146,6 +146,34 @@ XCTAssertEqualObjects(document.data, finalData); } +- (void)testCanMergeServerTimestamps { + FIRDocumentReference *doc = [[self.db collectionWithPath:@"rooms"] documentWithAutoID]; + + NSDictionary<NSString *, id> *initialData = @{ + @"updated" : @NO, + }; + NSDictionary<NSString *, id> *mergeData = + @{@"time" : [FIRFieldValue fieldValueForServerTimestamp]}; + + [self writeDocumentRef:doc data:initialData]; + + XCTestExpectation *completed = + [self expectationWithDescription:@"testCanMergeDataWithAnExistingDocumentUsingSet"]; + + [doc setData:mergeData + options:[FIRSetOptions merge] + completion:^(NSError *error) { + XCTAssertNil(error); + [completed fulfill]; + }]; + + [self awaitExpectations]; + + FIRDocumentSnapshot *document = [self readDocumentForRef:doc]; + XCTAssertEqual(@NO, document[@"updated"]); + XCTAssertTrue([document[@"time"] isKindOfClass:[NSDate class]]); +} + - (void)testMergeReplacesArrays { FIRDocumentReference *doc = [[self.db collectionWithPath:@"rooms"] documentWithAutoID]; @@ -155,7 +183,7 @@ @"topLevel" : @[ @"old", @"old" ], @"mapInArray" : @[ @{@"data" : @"old"} ] }; - NSDictionary<NSString *, id> *updateData = + NSDictionary<NSString *, id> *mergeData = @{ @"data" : @"new", @"topLevel" : @[ @"new" ], @"mapInArray" : @[ @{@"data" : @"new"} ] }; @@ -171,7 +199,7 @@ XCTestExpectation *completed = [self expectationWithDescription:@"testCanMergeDataWithAnExistingDocumentUsingSet"]; - [doc setData:updateData + [doc setData:mergeData options:[FIRSetOptions merge] completion:^(NSError *error) { XCTAssertNil(error); |