Disallow empty document fields (#4229)

Port of firebase/firebase-android-sdk#643.

Also make error messages align with Android's.
This commit is contained in:
Gil authored and GitHub committed 2019-11-04 17:03:10 -06:00
1 parent 0d64c5bf69
commit 38d9643a00
2 files changed
+22 -10

No files matched your search

@@ -263,23 +263,30 @@ namespace testutil = firebase::firestore::testutil;
- (void)testWritesWithReservedFieldsFail {
[self expectWrite:@{@"__baz__" : @1}
toFailWithReason:@"Document fields cannot begin and end with __ (found in field __baz__)"];
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
@"field __baz__)"];
[self expectWrite:@{@"foo" : @{@"__baz__" : @1}}
toFailWithReason:
@"Document fields cannot begin and end with __ (found in field foo.__baz__)"];
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
@"field foo.__baz__)"];
[self expectWrite:@{@"__baz__" : @{@"foo" : @1}}
toFailWithReason:@"Document fields cannot begin and end with __ (found in field __baz__)"];
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
@"field __baz__)"];
[self expectUpdate:@{@"foo.__baz__" : @1}
toFailWithReason:
@"Document fields cannot begin and end with __ (found in field foo.__baz__)"];
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
@"field foo.__baz__)"];
[self expectUpdate:@{@"__baz__.foo" : @1}
toFailWithReason:
@"Document fields cannot begin and end with __ (found in field __baz__.foo)"];
toFailWithReason:@"Invalid data. Document fields cannot begin and end with \"__\" (found in "
@"field __baz__.foo)"];
[self expectUpdate:@{@1 : @1}
toFailWithReason:@"Dictionary keys in updateData: must be NSStrings or FIRFieldPaths."];
}
- (void)testWritesMustNotContainEmptyFieldNames {
[self expectSet:@{@"" : @"foo"}
toFailWithReason:@"Invalid data. Document fields must not be empty (found in field ``)"];
}
- (void)testSetsWithFieldValueDeleteFail {
[self expectSet:@{@"foo" : [FIRFieldValue fieldValueForDelete]}
toFailWithReason:@"FieldValue.delete() can only be used with updateData() and setData() with "