Skip to content

Commit f212f33

Browse files
committed
Strip read only fields from serialized beforeSave response objects
1 parent 5176efb commit f212f33

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

spec/ParseAPI.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,27 @@ describe('miscellaneous', function() {
10621062
})
10631063
})
10641064

1065+
it('does not think objects are dirty after saving them', (done) => {
1066+
let headers = {
1067+
'Content-Type': 'application/json',
1068+
'X-Parse-Application-Id': 'test',
1069+
'X-Parse-REST-API-Key': 'rest'
1070+
};
1071+
let requestOptions = {
1072+
headers: headers,
1073+
url: 'http://localhost:8378/1/classes/AnObject',
1074+
json: true
1075+
};
1076+
let object = new Parse.Object('AnObject');
1077+
object.set('cool', true);
1078+
1079+
request.post(requestOptions, (err, res, body) => {
1080+
console.log(body);
1081+
expect(body.updatedAt).toBeUndefined();
1082+
done();
1083+
});
1084+
})
1085+
10651086
it('ignores _RevocableSession "header" send by JS SDK', (done) => {
10661087
let object = new Parse.Object('AnObject');
10671088
object.set('a', 'b');

spec/ParseHooks.spec.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ describe('Hooks', () => {
387387
Parse.Hooks.createTrigger("SomeRandomObject", "beforeSave" ,hookServerURL+"/BeforeSaveSome").then(function(){
388388
const obj = new Parse.Object("SomeRandomObject");
389389
return obj.save();
390-
}).then(function(res){
390+
}).then(function(res) {
391391
expect(triggerCount).toBe(1);
392392
return res.fetch();
393-
}).then(function(res){
393+
}).then(function(res) {
394394
expect(res.get("hello")).toEqual("world");
395395
done();
396396
}).fail((err) => {
@@ -400,6 +400,26 @@ describe('Hooks', () => {
400400
});
401401
});
402402

403+
it("beforeSave hooks should correctly handle responses containing entire object", (done) => {
404+
app.post("/BeforeSaveSome2", function(req, res) {
405+
var object = Parse.Object.fromJSON(req.body.object);
406+
object.set('hello', "world");
407+
res.json({success: object});
408+
});
409+
Parse.Hooks.createTrigger("SomeRandomObject2", "beforeSave" ,hookServerURL+"/BeforeSaveSome2").then(function(){
410+
const obj = new Parse.Object("SomeRandomObject2");
411+
return obj.save();
412+
}).then(function(res) {
413+
return res.save();
414+
}).then(function(res) {
415+
expect(res.get("hello")).toEqual("world");
416+
done();
417+
}).fail((err) => {
418+
fail(`Should not fail: ${JSON.stringify(err)}`);
419+
done();
420+
});
421+
});
422+
403423
it("should run the afterSave hook on the test server", (done) => {
404424
var triggerCount = 0;
405425
var newObjectId;

src/Controllers/HooksController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ function wrapToHTTPRequest(hook, key) {
205205
if (err) {
206206
return res.error(err);
207207
} else if (hook.triggerName === 'beforeSave') {
208+
delete result.createdAt;
209+
delete result.updatedAt;
208210
return res.success({object: result});
209211
} else {
210212
return res.success(result);

0 commit comments

Comments
 (0)