From 85567310d4fe76e6b5f1f291d7625cff547c6b40 Mon Sep 17 00:00:00 2001 From: Yuki Takeichi Date: Fri, 25 Nov 2016 23:20:06 +0900 Subject: [PATCH] Ignores createdAt when update (#3111) --- spec/{RestCreate.spec.js => rest.spec.js} | 31 +++++++++++++++++++++++ src/RestWrite.js | 3 +++ 2 files changed, 34 insertions(+) rename spec/{RestCreate.spec.js => rest.spec.js} (94%) diff --git a/spec/RestCreate.spec.js b/spec/rest.spec.js similarity index 94% rename from spec/RestCreate.spec.js rename to spec/rest.spec.js index 53d2f600..f396e173 100644 --- a/spec/RestCreate.spec.js +++ b/spec/rest.spec.js @@ -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(); + }); + }); + +}); diff --git a/src/RestWrite.js b/src/RestWrite.js index 7d4ba667..9a21bcc6 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -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 => {