diff --git a/spec/ParseInstallation.spec.js b/spec/ParseInstallation.spec.js index b11f1337e5..0a601be2df 100644 --- a/spec/ParseInstallation.spec.js +++ b/spec/ParseInstallation.spec.js @@ -1239,6 +1239,56 @@ describe('Installations', () => { }); }); + it('can use push with beforeSave', async () => { + const input = { + deviceToken: '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306', + deviceType: 'ios', + }; + await rest.create(config, auth.nobody(config), '_Installation', input) + const functions = { + beforeSave() {}, + afterSave() {} + } + spyOn(functions, 'beforeSave').and.callThrough(); + spyOn(functions, 'afterSave').and.callThrough(); + Parse.Cloud.beforeSave(Parse.Installation, functions.beforeSave); + Parse.Cloud.afterSave(Parse.Installation, functions.afterSave); + await Parse.Push.send({ + where: { + deviceType: 'ios', + }, + data: { + badge: 'increment', + alert: 'Hello world!', + }, + }); + + await Parse.Push.send({ + where: { + deviceType: 'ios', + }, + data: { + badge: 'increment', + alert: 'Hello world!', + }, + }); + + await Parse.Push.send({ + where: { + deviceType: 'ios', + }, + data: { + badge: 'increment', + alert: 'Hello world!', + }, + }); + await new Promise(resolve => setTimeout(resolve, 1000)); + const installation = await new Parse.Query(Parse.Installation).first({useMasterKey: true}); + expect(installation.get('badge')).toEqual(3); + expect(functions.beforeSave).not.toHaveBeenCalled(); + expect(functions.afterSave).not.toHaveBeenCalled(); + }); + // TODO: Look at additional tests from installation_collection_test.go:882 // TODO: Do we need to support _tombstone disabling of installations? // TODO: Test deletion, badge increments diff --git a/src/RestWrite.js b/src/RestWrite.js index 2be833ad30..8883d6197d 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -217,7 +217,7 @@ RestWrite.prototype.validateSchema = function () { // Runs any beforeSave triggers against this operation. // Any change leads to our data being mutated. RestWrite.prototype.runBeforeSaveTrigger = function () { - if (this.response) { + if (this.response || this.runOptions.many) { return; } @@ -1522,7 +1522,7 @@ RestWrite.prototype.runDatabaseOperation = function () { // Returns nothing - doesn't wait for the trigger. RestWrite.prototype.runAfterSaveTrigger = function () { - if (!this.response || !this.response.response) { + if (!this.response || !this.response.response || this.runOptions.many) { return; }