use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testMultipleMutationsAreSquashed.
// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testMultipleMutationsAreSquashed() {
// INPUT:
// SetMutation -> SetMutation -> TransformMutation -> DeleteMutation -> PatchMutation ->
// TransformMutation -> PatchMutation
// OUTPUT (squashed):
// SetMutation -> SetMutation -> DeleteMutation -> PatchMutation -> PatchMutation
WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(setProto, setProto, transformProto, deleteProto, patchProto, transformProto, patchProto)).setLocalWriteTime(writeTimeProto).build();
MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
assertEquals(5, decoded.getMutations().size());
List<Write> allExpected = asList(new TestWriteBuilder().addSet().build(), new TestWriteBuilder().addSet().addUpdateTransforms().build(), new TestWriteBuilder().addDelete().build(), new TestWriteBuilder().addPatch().addUpdateTransforms().build(), new TestWriteBuilder().addPatch().build());
for (int i = 0; i < decoded.getMutations().size(); i++) {
Mutation mutation = decoded.getMutations().get(i);
Write encoded = remoteSerializer.encodeMutation(mutation);
assertEquals(allExpected.get(i), encoded);
}
}
use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testDeleteAndTransformThrowError.
// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testDeleteAndTransformThrowError() {
WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(deleteProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
assertThrows(AssertionError.class, () -> serializer.decodeMutationBatch(batchProto));
}
use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testSetMutationAndTransFormMutationAreSquashed.
// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testSetMutationAndTransFormMutationAreSquashed() {
WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(setProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
assertEquals(1, decoded.getMutations().size());
assertTrue(decoded.getMutations().get(0) instanceof SetMutation);
Write encoded = remoteSerializer.encodeMutation(decoded.getMutations().get(0));
Write expected = new TestWriteBuilder().addSet().addUpdateTransforms().build();
assertEquals(expected, encoded);
}
use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testPatchMutationAndTransFormMutationAreSquashed.
// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testPatchMutationAndTransFormMutationAreSquashed() {
WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(patchProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
MutationBatch decoded = serializer.decodeMutationBatch(batchProto);
assertEquals(1, decoded.getMutations().size());
assertTrue(decoded.getMutations().get(0) instanceof PatchMutation);
Write encoded = remoteSerializer.encodeMutation(decoded.getMutations().get(0));
Write expected = new TestWriteBuilder().addPatch().addUpdateTransforms().build();
assertEquals(expected, encoded);
}
use of com.google.firebase.firestore.proto.WriteBatch in project firebase-android-sdk by firebase.
the class LocalSerializerTest method testTransformAndTransformThrowError.
// TODO(b/174608374): Remove these tests once we perform a schema migration.
@Test
public void testTransformAndTransformThrowError() {
WriteBatch batchProto = com.google.firebase.firestore.proto.WriteBatch.newBuilder().setBatchId(42).addAllWrites(asList(transformProto, transformProto)).setLocalWriteTime(writeTimeProto).build();
assertThrows(AssertionError.class, () -> serializer.decodeMutationBatch(batchProto));
}
Aggregations