Skip to content

Commit

Permalink
Including previous data when we encounter a transform (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Jan 30, 2018
1 parent 0f7a975 commit f8e1d23
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ class DocumentSnapshot {
if (!is.defined(target[key])) {
if (isLast) {
if (DocumentTransform.isTransformSentinel(value)) {
return null;
// If there is already data at this path, we need to retain it.
// Otherwise, we don't include it in the DocumentSnapshot.
return !is.empty(target) ? target : null;
}
// The merge is done.
const leafNode = DocumentSnapshot.encodeValue(value);
Expand Down
32 changes: 32 additions & 0 deletions test/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,38 @@ describe('update document', function() {
]);
});

it('with nested field and document transform ', function() {
firestore.api.Firestore._commit = function(request, options, callback) {
requestEquals(
request,
update(
document('foo', {
mapValue: {
fields: {
bar: {
stringValue: 'include',
valueType: 'stringValue',
},
},
},
valueType: 'mapValue',
}),
updateMask('foo.bar', 'foo.delete')
)
);

callback(null, writeResult(1));
};
return firestore
.doc('collectionId/documentId')
.update(
'foo.bar',
'include',
'foo.delete',
Firestore.FieldValue.delete()
);
});

it('with field with dot ', function() {
firestore.api.Firestore._commit = function(request, options, callback) {
requestEquals(request, update(document('a.b', 'c'), updateMask('`a.b`')));
Expand Down

0 comments on commit f8e1d23

Please sign in to comment.