12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- package com .google .firebase .firestore .model ;
15
+ package com .google .firebase .firestore .model . mutation ;
16
16
17
17
import static com .google .firebase .firestore .testutil .TestUtil .deleteMutation ;
18
18
import static com .google .firebase .firestore .testutil .TestUtil .deletedDoc ;
39
39
import com .google .common .collect .Sets ;
40
40
import com .google .firebase .Timestamp ;
41
41
import com .google .firebase .firestore .FieldValue ;
42
- import com .google .firebase .firestore .model .mutation .ArrayTransformOperation ;
43
- import com .google .firebase .firestore .model .mutation .DeleteMutation ;
44
- import com .google .firebase .firestore .model .mutation .FieldMask ;
45
- import com .google .firebase .firestore .model .mutation .FieldTransform ;
46
- import com .google .firebase .firestore .model .mutation .Mutation ;
47
- import com .google .firebase .firestore .model .mutation .MutationResult ;
48
- import com .google .firebase .firestore .model .mutation .PatchMutation ;
49
- import com .google .firebase .firestore .model .mutation .Precondition ;
50
- import com .google .firebase .firestore .model .mutation .SetMutation ;
42
+ import com .google .firebase .firestore .model .DocumentKey ;
43
+ import com .google .firebase .firestore .model .FieldPath ;
44
+ import com .google .firebase .firestore .model .MutableDocument ;
45
+ import com .google .firebase .firestore .model .ObjectValue ;
46
+ import com .google .firebase .firestore .model .ServerTimestamps ;
47
+ import com .google .firebase .firestore .model .SnapshotVersion ;
48
+ import com .google .firebase .firestore .model .Values ;
51
49
import com .google .firestore .v1 .Value ;
52
50
import java .util .Arrays ;
53
51
import java .util .Collection ;
@@ -89,13 +87,13 @@ public void testAppliesPatchToDocuments() {
89
87
90
88
@ Test
91
89
public void testAppliesPatchWithMergeToDocuments () {
92
- MutableDocument mergeDoc = deletedDoc ("collection/key" , 1 );
90
+ MutableDocument mergeDoc = deletedDoc ("collection/key" , 0 );
93
91
Mutation upsert =
94
92
mergeMutation (
95
93
"collection/key" , map ("foo.bar" , "new-bar-value" ), Arrays .asList (field ("foo.bar" )));
96
94
upsert .applyToLocalView (mergeDoc , /* previousMask= */ null , Timestamp .now ());
97
95
Map <String , Object > expectedData = map ("foo" , map ("bar" , "new-bar-value" ));
98
- assertEquals (doc ("collection/key" , 1 , expectedData ).setHasLocalMutations (), mergeDoc );
96
+ assertEquals (doc ("collection/key" , 0 , expectedData ).setHasLocalMutations (), mergeDoc );
99
97
}
100
98
101
99
@ Test
@@ -990,7 +988,7 @@ private int runPermutationTests(List<MutableDocument> docs, List<Mutation> mutat
990
988
Collections2 .permutations (Lists .newArrayList (mutations ));
991
989
for (MutableDocument doc : docs ) {
992
990
for (List <Mutation > permutation : permutations ) {
993
- verifyOverlayRoundTrips (doc , permutation .toArray (new Mutation []{}));
991
+ verifyOverlayRoundTrips (doc , permutation .toArray (new Mutation [] {}));
994
992
testCases += 1 ;
995
993
}
996
994
}
@@ -1029,25 +1027,26 @@ private void verifyOverlayRoundTrips(MutableDocument doc, Mutation... mutations)
1029
1027
}
1030
1028
1031
1029
Mutation overlay = null ;
1032
- boolean isLatencyCompensatedDelete = docForMutations .getVersion ().equals (SnapshotVersion .NONE ) && docForMutations .isNoDocument ();
1030
+ boolean isLatencyCompensatedDelete =
1031
+ docForMutations .getVersion ().equals (SnapshotVersion .NONE ) && docForMutations .isNoDocument ();
1033
1032
if (docForMutations .hasLocalMutations () || isLatencyCompensatedDelete ) {
1034
- overlay = getOverlayMutation (docForMutations , mask );
1033
+ overlay = getOverlayMutation (docForMutations , mask );
1035
1034
overlay .applyToLocalView (docForOverlay , /* previousMask= */ null , now );
1036
1035
}
1037
1036
1038
1037
assertEquals (
1039
- getDescription (doc , Arrays .asList (mutations ), overlay ),
1040
- docForOverlay ,
1041
- docForMutations );
1038
+ getDescription (doc , Arrays .asList (mutations ), overlay ), docForOverlay , docForMutations );
1042
1039
}
1043
1040
1044
1041
// TODO(Overlay): This is production code, find a place for this.
1045
1042
private Mutation getOverlayMutation (MutableDocument doc , @ Nullable FieldMask mask ) {
1046
1043
if (mask == null ) {
1047
1044
if (doc .isNoDocument ()) {
1048
- return new DeleteMutation (doc .getKey (), Precondition .NONE );
1045
+ return new DeleteMutation (doc .getKey (), Precondition .NONE )
1046
+ .withPostMutationVersion (doc .getVersion ());
1049
1047
} else {
1050
- return new SetMutation (doc .getKey (), doc .getData (), Precondition .NONE );
1048
+ return new SetMutation (doc .getKey (), doc .getData (), Precondition .NONE )
1049
+ .withPostMutationVersion (doc .getVersion ());
1051
1050
}
1052
1051
} else {
1053
1052
ObjectValue docValue = doc .getData ();
@@ -1072,9 +1071,9 @@ private Mutation getOverlayMutation(MutableDocument doc, @Nullable FieldMask mas
1072
1071
maskSet .add (path );
1073
1072
}
1074
1073
}
1075
- return
1076
- new PatchMutation (
1077
- doc . getKey (), patchValue , FieldMask . fromSet ( maskSet ), Precondition . NONE );
1074
+ return new PatchMutation (
1075
+ doc . getKey (), patchValue , FieldMask . fromSet ( maskSet ), Precondition . NONE )
1076
+ . withPostMutationVersion ( doc . getVersion () );
1078
1077
}
1079
1078
}
1080
1079
}
0 commit comments