Skip to content

Commit

Permalink
Merge pull request #865 from ParsePlatform/fosco.457
Browse files Browse the repository at this point in the history
beforeSave changes should propagate to the response
  • Loading branch information
gfosco committed Mar 6, 2016
2 parents b3a52fb + 3266d59 commit 7e153d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,23 @@ describe('miscellaneous', function() {
});
});

it('beforeSave change propagates through the save response', (done) => {
Parse.Cloud.beforeSave('ChangingObject', function(request, response) {
request.object.set('foo', 'baz');
response.success();
});
let obj = new Parse.Object('ChangingObject');
obj.save({ foo: 'bar' }).then((objAgain) => {
expect(objAgain.get('foo')).toEqual('baz');
Parse.Cloud._removeHook("Triggers", "beforeSave", "ChangingObject");
done();
}, (e) => {
Parse.Cloud._removeHook("Triggers", "beforeSave", "ChangingObject");
fail('Should not have failed to save.');
done();
});
});

it('dedupes an installation properly and returns updatedAt', (done) => {
let headers = {
'Content-Type': 'application/json',
Expand Down
4 changes: 4 additions & 0 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ RestWrite.prototype.runBeforeTrigger = function() {
}).then((response) => {
if (response && response.object) {
this.data = response.object;
this.storage['changedByTrigger'] = true;
// We should delete the objectId for an update write
if (this.query && this.query.objectId) {
delete this.data.objectId
Expand Down Expand Up @@ -806,6 +807,9 @@ RestWrite.prototype.runDatabaseOperation = function() {
objectId: this.data.objectId,
createdAt: this.data.createdAt
};
if (this.storage['changedByTrigger']) {
Object.assign(resp, this.data);
}
if (this.storage['token']) {
resp.sessionToken = this.storage['token'];
}
Expand Down

0 comments on commit 7e153d4

Please sign in to comment.