Skip to content

Commit 8556731

Browse files
yuki-takeichiflovilmart
authored andcommitted
Ignores createdAt when update (#3111)
1 parent 8f1c1f4 commit 8556731

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

spec/RestCreate.spec.js renamed to spec/rest.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,34 @@ describe('rest create', () => {
420420
})
421421
});
422422
});
423+
424+
describe('rest update', () => {
425+
426+
it('ignores createdAt', done => {
427+
const nobody = auth.nobody(config);
428+
const className = 'Foo';
429+
const newCreatedAt = new Date('1970-01-01T00:00:00.000Z');
430+
431+
rest.create(config, nobody, className, {}).then(res => {
432+
const objectId = res.response.objectId;
433+
const restObject = {
434+
createdAt: {__type: "Date", iso: newCreatedAt}, // should be ignored
435+
};
436+
437+
return rest.update(config, nobody, className, objectId, restObject).then(() => {
438+
const restWhere = {
439+
objectId: objectId,
440+
};
441+
return rest.find(config, nobody, className, restWhere, {});
442+
});
443+
}).then(res2 => {
444+
const updatedObject = res2.results[0];
445+
expect(new Date(updatedObject.createdAt)).not.toEqual(newCreatedAt);
446+
done();
447+
}).then(done).catch(err => {
448+
fail(err);
449+
done();
450+
});
451+
});
452+
453+
});

src/RestWrite.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,9 @@ RestWrite.prototype.runDatabaseOperation = function() {
842842
if (this.className === '_User' && this.data._hashed_password && this.config.passwordPolicy && this.config.passwordPolicy.maxPasswordAge) {
843843
this.data._password_changed_at = Parse._encode(new Date());
844844
}
845+
// Ignore createdAt when update
846+
delete this.data.createdAt;
847+
845848
// Run an update
846849
return this.config.database.update(this.className, this.query, this.data, this.runOptions)
847850
.then(response => {

0 commit comments

Comments
 (0)