Skip to content

Ignores createdAt when update #3111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions spec/RestCreate.spec.js → spec/rest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,34 @@ describe('rest create', () => {
})
});
});

describe('rest update', () => {

it('ignores createdAt', done => {
const nobody = auth.nobody(config);
const className = 'Foo';
const newCreatedAt = new Date('1970-01-01T00:00:00.000Z');

rest.create(config, nobody, className, {}).then(res => {
const objectId = res.response.objectId;
const restObject = {
createdAt: {__type: "Date", iso: newCreatedAt}, // should be ignored
};

return rest.update(config, nobody, className, objectId, restObject).then(() => {
const restWhere = {
objectId: objectId,
};
return rest.find(config, nobody, className, restWhere, {});
});
}).then(res2 => {
const updatedObject = res2.results[0];
expect(new Date(updatedObject.createdAt)).not.toEqual(newCreatedAt);
done();
}).then(done).catch(err => {
fail(err);
done();
});
});

});
3 changes: 3 additions & 0 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ RestWrite.prototype.runDatabaseOperation = function() {
if (this.className === '_User' && this.data._hashed_password && this.config.passwordPolicy && this.config.passwordPolicy.maxPasswordAge) {
this.data._password_changed_at = Parse._encode(new Date());
}
// Ignore createdAt when update
delete this.data.createdAt;

// Run an update
return this.config.database.update(this.className, this.query, this.data, this.runOptions)
.then(response => {
Expand Down