Strip read only fields from serialized beforeSave response objects (#1964)

This commit is contained in:
Tyler Brock
2016-05-31 17:00:41 -07:00
committed by Drew
parent 5176efbe16
commit 04172eda5a
2 changed files with 24 additions and 2 deletions

View File

@@ -387,10 +387,10 @@ describe('Hooks', () => {
Parse.Hooks.createTrigger("SomeRandomObject", "beforeSave" ,hookServerURL+"/BeforeSaveSome").then(function(){
const obj = new Parse.Object("SomeRandomObject");
return obj.save();
}).then(function(res){
}).then(function(res) {
expect(triggerCount).toBe(1);
return res.fetch();
}).then(function(res){
}).then(function(res) {
expect(res.get("hello")).toEqual("world");
done();
}).fail((err) => {
@@ -400,6 +400,26 @@ describe('Hooks', () => {
});
});
it("beforeSave hooks should correctly handle responses containing entire object", (done) => {
app.post("/BeforeSaveSome2", function(req, res) {
var object = Parse.Object.fromJSON(req.body.object);
object.set('hello', "world");
res.json({success: object});
});
Parse.Hooks.createTrigger("SomeRandomObject2", "beforeSave" ,hookServerURL+"/BeforeSaveSome2").then(function(){
const obj = new Parse.Object("SomeRandomObject2");
return obj.save();
}).then(function(res) {
return res.save();
}).then(function(res) {
expect(res.get("hello")).toEqual("world");
done();
}).fail((err) => {
fail(`Should not fail: ${JSON.stringify(err)}`);
done();
});
});
it("should run the afterSave hook on the test server", (done) => {
var triggerCount = 0;
var newObjectId;

View File

@@ -205,6 +205,8 @@ function wrapToHTTPRequest(hook, key) {
if (err) {
return res.error(err);
} else if (hook.triggerName === 'beforeSave') {
delete result.createdAt;
delete result.updatedAt;
return res.success({object: result});
} else {
return res.success(result);