@@ -560,37 +560,53 @@ apiDescribe('Validation:', persistence => {
560
560
) ;
561
561
562
562
validationIt ( persistence , 'Field paths must not have empty segments' , db => {
563
- const badFieldPaths = [ '' , 'foo..baz' , '.foo' , 'foo.' ] ;
564
- const promises = [ ] ;
565
- for ( const fieldPath of badFieldPaths ) {
566
- const reason =
567
- `Invalid field path (${ fieldPath } ). Paths must not be ` +
568
- `empty, begin with '.', end with '.', or contain '..'` ;
569
- promises . push ( expectFieldPathToFail ( db , fieldPath , reason ) ) ;
570
- }
571
- return Promise . all ( promises ) ;
563
+ const docRef = db . collection ( 'test' ) . doc ( ) ;
564
+ return docRef
565
+ . set ( { test : 1 } )
566
+ . then ( ( ) => {
567
+ return docRef . get ( ) ;
568
+ } )
569
+ . then ( snapshot => {
570
+ const badFieldPaths = [ '' , 'foo..baz' , '.foo' , 'foo.' ] ;
571
+ const promises = [ ] ;
572
+ for ( const fieldPath of badFieldPaths ) {
573
+ const reason =
574
+ `Invalid field path (${ fieldPath } ). Paths must not be ` +
575
+ `empty, begin with '.', end with '.', or contain '..'` ;
576
+ promises . push ( expectFieldPathToFail ( snapshot , fieldPath , reason ) ) ;
577
+ }
578
+ return Promise . all ( promises ) ;
579
+ } ) ;
572
580
} ) ;
573
581
574
582
validationIt (
575
583
persistence ,
576
584
'Field paths must not have invalid segments' ,
577
585
db => {
578
- const badFieldPaths = [
579
- 'foo~bar' ,
580
- 'foo*bar' ,
581
- 'foo/bar' ,
582
- 'foo[1' ,
583
- 'foo]1' ,
584
- 'foo[1]'
585
- ] ;
586
- const promises = [ ] ;
587
- for ( const fieldPath of badFieldPaths ) {
588
- const reason =
589
- `Invalid field path (${ fieldPath } ). Paths must not ` +
590
- `contain '~', '*', '/', '[', or ']'` ;
591
- promises . push ( expectFieldPathToFail ( db , fieldPath , reason ) ) ;
592
- }
593
- return Promise . all ( promises ) ;
586
+ const docRef = db . collection ( 'test' ) . doc ( ) ;
587
+ return docRef
588
+ . set ( { test : 1 } )
589
+ . then ( ( ) => {
590
+ return docRef . get ( ) ;
591
+ } )
592
+ . then ( snapshot => {
593
+ const badFieldPaths = [
594
+ 'foo~bar' ,
595
+ 'foo*bar' ,
596
+ 'foo/bar' ,
597
+ 'foo[1' ,
598
+ 'foo]1' ,
599
+ 'foo[1]'
600
+ ] ;
601
+ const promises = [ ] ;
602
+ for ( const fieldPath of badFieldPaths ) {
603
+ const reason =
604
+ `Invalid field path (${ fieldPath } ). Paths must not ` +
605
+ `contain '~', '*', '/', '[', or ']'` ;
606
+ promises . push ( expectFieldPathToFail ( snapshot , fieldPath , reason ) ) ;
607
+ }
608
+ return Promise . all ( promises ) ;
609
+ } ) ;
594
610
}
595
611
) ;
596
612
@@ -953,37 +969,33 @@ function expectWriteToFail(
953
969
* they fail with the specified reason.
954
970
*/
955
971
function expectFieldPathToFail (
956
- db : firestore . FirebaseFirestore ,
972
+ snapshot : firestore . DocumentSnapshot ,
957
973
path : string ,
958
974
reason : string
959
975
) : Promise < void > {
960
976
// Get an arbitrary snapshot we can use for testing.
961
- const docRef = db . collection ( 'test' ) . doc ( ) ;
962
- return docRef
963
- . set ( { test : 1 } )
964
- . then ( ( ) => {
965
- return docRef . get ( ) ;
966
- } )
967
- . then ( snapshot => {
968
- // Snapshot paths.
969
- expect ( ( ) => snapshot . get ( path ) ) . to . throw (
970
- 'Function DocumentSnapshot.get() called with invalid data. ' + reason
971
- ) ;
977
+ return Promise . resolve ( ) . then ( ( ) => {
978
+ // Snapshot paths.
979
+ expect ( ( ) => snapshot . get ( path ) ) . to . throw (
980
+ 'Function DocumentSnapshot.get() called with invalid data. ' + reason
981
+ ) ;
972
982
973
- // Query filter / order fields.
974
- const coll = db . collection ( 'test-collection' ) ;
975
- // <=, etc omitted for brevity since the code path is trivially
976
- // shared.
977
- expect ( ( ) => coll . where ( path , '==' , 1 ) ) . to . throw (
978
- 'Function Query.where() called with invalid data. ' + reason
979
- ) ;
980
- expect ( ( ) => coll . orderBy ( path ) ) . to . throw (
981
- 'Function Query.orderBy() called with invalid data. ' + reason
982
- ) ;
983
+ const db = snapshot . ref . firestore ;
983
984
984
- // Update paths.
985
- const data = { } as { [ field : string ] : number } ;
986
- data [ path ] = 1 ;
987
- return expectUpdateToFail ( db , data , reason ) ;
988
- } ) ;
985
+ // Query filter / order fields.
986
+ const coll = db . collection ( 'test-collection' ) ;
987
+ // <=, etc omitted for brevity since the code path is trivially
988
+ // shared.
989
+ expect ( ( ) => coll . where ( path , '==' , 1 ) ) . to . throw (
990
+ 'Function Query.where() called with invalid data. ' + reason
991
+ ) ;
992
+ expect ( ( ) => coll . orderBy ( path ) ) . to . throw (
993
+ 'Function Query.orderBy() called with invalid data. ' + reason
994
+ ) ;
995
+
996
+ // Update paths.
997
+ const data = { } as { [ field : string ] : number } ;
998
+ data [ path ] = 1 ;
999
+ return expectUpdateToFail ( db , data , reason ) ;
1000
+ } ) ;
989
1001
}
0 commit comments