use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testAppliesServerAckedIncrementTransformToDocuments.
@Test
public void testAppliesServerAckedIncrementTransformToDocuments() {
Map<String, Object> data = map("sum", 1);
MutableDocument transformedDoc = doc("collection/key", 1, data);
Mutation transform = setMutation("collection/key", map("sum", FieldValue.increment(2)));
MutationResult mutationResult = new MutationResult(version(1), Collections.singletonList(wrap(3L)));
transform.applyToRemoteDocument(transformedDoc, mutationResult);
Map<String, Object> expectedData = map("sum", 3L);
assertEquals(doc("collection/key", 1, expectedData).setHasCommittedMutations(), transformedDoc);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testOverlayWithPatchThenPatchToDeleteField.
@Test
public void testOverlayWithPatchThenPatchToDeleteField() {
MutableDocument doc = doc("collection/key", 1, map("foo", 1));
Mutation patch = patchMutation("collection/key", map("foo", "foo-patched-value", "bar.baz", FieldValue.increment(1)));
Mutation patchToDeleteField = patchMutation("collection/key", map("foo", "foo-patched-value", "bar.baz", FieldValue.delete()));
verifyOverlayRoundTrips(doc, patch, patchToDeleteField);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testNumericIncrementBaseValue.
@Test
public void testNumericIncrementBaseValue() {
Map<String, Object> allValues = map("ignore", "foo", "double", 42.0, "long", 42, "string", "foo", "map", map());
allValues.put("nested", new HashMap<>(allValues));
MutableDocument baseDoc = doc("collection/key", 1, allValues);
Map<String, Object> allTransforms = map("double", FieldValue.increment(1), "long", FieldValue.increment(1), "string", FieldValue.increment(1), "map", FieldValue.increment(1), "missing", FieldValue.increment(1));
allTransforms.put("nested", new HashMap<>(allTransforms));
Mutation mutation = patchMutation("collection/key", allTransforms);
ObjectValue baseValue = mutation.extractTransformBaseValue(baseDoc);
Value expected = wrap(map("double", 42.0, "long", 42, "string", 0, "map", 0, "missing", 0, "nested", map("double", 42.0, "long", 42, "string", 0, "map", 0, "missing", 0)));
assertTrue(Values.equals(expected, baseValue.get(FieldPath.EMPTY_PATH)));
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testDeleteDeletes.
@Test
public void testDeleteDeletes() {
Map<String, Object> data = map("foo", "bar");
MutableDocument deletedDoc = doc("collection/key", 1, data);
Mutation delete = deleteMutation("collection/key");
delete.applyToLocalView(deletedDoc, /* previousMask= */
null, Timestamp.now());
assertEquals(deletedDoc("collection/key", 1).setHasLocalMutations(), deletedDoc);
}
use of com.google.firebase.firestore.model.MutableDocument in project firebase-android-sdk by firebase.
the class MutationTest method testNonTransformMutationBaseValue.
@Test
public void testNonTransformMutationBaseValue() {
Map<String, Object> data = map("foo", "foo");
MutableDocument baseDoc = doc("collection/key", 1, data);
Mutation set = setMutation("collection/key", map("foo", "bar"));
assertNull(set.extractTransformBaseValue(baseDoc));
Mutation patch = patchMutation("collection/key", map("foo", "bar"));
assertNull(patch.extractTransformBaseValue(baseDoc));
Mutation delete = deleteMutation("collection/key");
assertNull(delete.extractTransformBaseValue(baseDoc));
}
Aggregations