diff options
author | Gil <mcg@google.com> | 2017-10-16 15:56:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-16 15:56:19 -0700 |
commit | a64495a33ba345e5580f0579aae49a23d0797ba6 (patch) | |
tree | d8d9a25e382b9326050a2fbd495e1a95664b27d4 /Firestore/Example/Tests/Integration/API/FIRValidationTests.m | |
parent | 2b40693be4c9aa2c94b668fb144c6993f557b8d6 (diff) |
Fix validation of nested arrays to allow indirect nesting (#377)
Diffstat (limited to 'Firestore/Example/Tests/Integration/API/FIRValidationTests.m')
-rw-r--r-- | Firestore/Example/Tests/Integration/API/FIRValidationTests.m | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/Firestore/Example/Tests/Integration/API/FIRValidationTests.m b/Firestore/Example/Tests/Integration/API/FIRValidationTests.m index 1ba1d7a..e4e7cd1 100644 --- a/Firestore/Example/Tests/Integration/API/FIRValidationTests.m +++ b/Firestore/Example/Tests/Integration/API/FIRValidationTests.m @@ -161,13 +161,66 @@ } } -- (void)testWritesWithNestedArraysFail { +- (void)testWritesWithDirectlyNestedArraysFail { [self expectWrite:@{ @"nested-array" : @[ @1, @[ @2 ] ] } toFailWithReason:@"Nested arrays are not supported"]; } +- (void)testWritesWithIndirectlyNestedArraysSucceed { + NSDictionary<NSString *, id> *data = @{ @"nested-array" : @[ @1, @{@"foo" : @[ @2 ]} ] }; + + FIRDocumentReference *ref = [self documentRef]; + FIRDocumentReference *ref2 = [self documentRef]; + + XCTestExpectation *expectation = [self expectationWithDescription:@"setData"]; + [ref setData:data + completion:^(NSError *_Nullable error) { + XCTAssertNil(error); + [expectation fulfill]; + }]; + [self awaitExpectations]; + + expectation = [self expectationWithDescription:@"batch.setData"]; + [[[ref.firestore batch] setData:data forDocument:ref] + commitWithCompletion:^(NSError *_Nullable error) { + XCTAssertNil(error); + [expectation fulfill]; + }]; + [self awaitExpectations]; + + expectation = [self expectationWithDescription:@"updateData"]; + [ref updateData:data + completion:^(NSError *_Nullable error) { + XCTAssertNil(error); + [expectation fulfill]; + }]; + [self awaitExpectations]; + + expectation = [self expectationWithDescription:@"batch.updateData"]; + [[[ref.firestore batch] updateData:data forDocument:ref] + commitWithCompletion:^(NSError *_Nullable error) { + XCTAssertNil(error); + [expectation fulfill]; + }]; + [self awaitExpectations]; + + XCTestExpectation *transactionDone = [self expectationWithDescription:@"transaction done"]; + [ref.firestore runTransactionWithBlock:^id(FIRTransaction *transaction, NSError **pError) { + // Note ref2 does not exist at this point so set that and update ref. + [transaction updateData:data forDocument:ref]; + [transaction setData:data forDocument:ref2]; + return nil; + } + completion:^(id result, NSError *error) { + // ends up being a no-op transaction. + XCTAssertNil(error); + [transactionDone fulfill]; + }]; + [self awaitExpectations]; +} + - (void)testWritesWithInvalidTypesFail { [self expectWrite:@{ @"foo" : @{@"bar" : self} |