From e4abe61c8b5799ccf71780acfbc4b1787a886981 Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Sun, 29 May 2016 10:50:36 -0400 Subject: [PATCH] Adds failing test with other use case - That test fails on parse.com as well --- spec/CloudCode.spec.js | 29 +++++++++++++++++++++++++++++ src/RestWrite.js | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index 34ce628a34..1efc75f90f 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -645,4 +645,33 @@ describe('Cloud Code', () => { done(); }); }); + + it('should fully delete objects when using `unset` with beforeSave (regression test for #1840)', done => { + var TestObject = Parse.Object.extend('TestObject'); + var BeforeSaveObject = Parse.Object.extend('BeforeSaveChanged'); + + Parse.Cloud.beforeSave('BeforeSaveChanged', (req, res) => { + var object = req.object; + object.set('before', 'save'); + object.unset('remove'); + res.success(); + }); + + let object; + let testObject = new TestObject({key: 'value'}); + testObject.save().then(() => { + object = new BeforeSaveObject(); + return object.save().then(() => { + object.set({remove:testObject}) + return object.save(); + }); + }).then((objectAgain) => { + expect(objectAgain.get('remove')).toBeUndefined(); + expect(object.get('remove')).toBeUndefined(); + done(); + }).fail((err) => { + console.error(err); + done(); + }) + }); }); diff --git a/src/RestWrite.js b/src/RestWrite.js index bc812d3a1c..acf364719c 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -858,7 +858,7 @@ function updateResponseWithData(response, data) { let dataValue = data[fieldName]; let responseValue = response[fieldName]; if (dataValue && dataValue.__op === 'Delete') { - delete response[fieldName]; + response[fieldName] = undefined; } else { response[fieldName] = responseValue || dataValue; }