use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method assertRoundTripForMutation.
private void assertRoundTripForMutation(Mutation mutation, Write proto) {
Write actualProto = serializer.encodeMutation(mutation);
assertEquals(proto, actualProto);
Mutation actualMutation = serializer.decodeMutation(proto);
assertEquals(mutation, actualMutation);
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesArrayMutations.
@Test
public void testEncodesArrayMutations() {
Mutation mutation = setMutation("docs/1", map("a", com.google.firebase.firestore.FieldValue.arrayUnion("a", 2), "bar", com.google.firebase.firestore.FieldValue.arrayRemove(map("x", 1))));
Write expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1")).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("a").setAppendMissingElements(ArrayValue.newBuilder().addValues(wrap("a")).addValues(wrap(2)))).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("bar").setRemoveAllFromArray(ArrayValue.newBuilder().addValues(wrap(map("x", 1))))).build();
assertRoundTripForMutation(mutation, expected);
mutation = patchMutation("docs/1", map("a", com.google.firebase.firestore.FieldValue.arrayUnion("a", 2), "bar.baz", com.google.firebase.firestore.FieldValue.arrayRemove(map("x", 1))));
expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1")).setUpdateMask(DocumentMask.newBuilder().build()).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("a").setAppendMissingElements(ArrayValue.newBuilder().addValues(wrap("a")).addValues(wrap(2)))).addUpdateTransforms(FieldTransform.newBuilder().setFieldPath("bar.baz").setRemoveAllFromArray(ArrayValue.newBuilder().addValues(wrap(map("x", 1))))).setCurrentDocument(Precondition.newBuilder().setExists(true)).build();
assertRoundTripForMutation(mutation, expected);
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesPatchMutation.
@Test
public void testEncodesPatchMutation() {
Mutation mutation = patchMutation("docs/1", map("key", "value", "key2", true));
Write expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1").putFields("key", Value.newBuilder().setStringValue("value").build()).putFields("key2", Value.newBuilder().setBooleanValue(true).build())).setUpdateMask(DocumentMask.newBuilder().addAllFieldPaths(asList("key", "key2"))).setCurrentDocument(Precondition.newBuilder().setExists(true)).build();
assertRoundTripForMutation(mutation, expected);
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodeSetMutation.
@Test
public void testEncodeSetMutation() {
Mutation mutation = setMutation("docs/1", map("key", "value"));
Write expected = Write.newBuilder().setUpdate(Document.newBuilder().setName("projects/p/databases/d/documents/docs/1").putFields("key", Value.newBuilder().setStringValue("value").build())).build();
assertRoundTripForMutation(mutation, expected);
}
use of com.google.firebase.firestore.model.mutation.Mutation in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodeDeleteMutation.
@Test
public void testEncodeDeleteMutation() {
Mutation mutation = deleteMutation("docs/1");
Write expected = Write.newBuilder().setDelete("projects/p/databases/d/documents/docs/1").build();
assertRoundTripForMutation(mutation, expected);
}
Aggregations