beforeSave changes should propagate to the response
This commit is contained in:
@@ -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) => {
|
it('dedupes an installation properly and returns updatedAt', (done) => {
|
||||||
let headers = {
|
let headers = {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ RestWrite.prototype.runBeforeTrigger = function() {
|
|||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
if (response && response.object) {
|
if (response && response.object) {
|
||||||
this.data = response.object;
|
this.data = response.object;
|
||||||
|
this.storage['changedByTrigger'] = true;
|
||||||
// We should delete the objectId for an update write
|
// We should delete the objectId for an update write
|
||||||
if (this.query && this.query.objectId) {
|
if (this.query && this.query.objectId) {
|
||||||
delete this.data.objectId
|
delete this.data.objectId
|
||||||
@@ -806,6 +807,9 @@ RestWrite.prototype.runDatabaseOperation = function() {
|
|||||||
objectId: this.data.objectId,
|
objectId: this.data.objectId,
|
||||||
createdAt: this.data.createdAt
|
createdAt: this.data.createdAt
|
||||||
};
|
};
|
||||||
|
if (this.storage['changedByTrigger']) {
|
||||||
|
Object.assign(resp, this.data);
|
||||||
|
}
|
||||||
if (this.storage['token']) {
|
if (this.storage['token']) {
|
||||||
resp.sessionToken = this.storage['token'];
|
resp.sessionToken = this.storage['token'];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user