Skip to content

Commit

Permalink
fix: push notifications badge doesn't update with Installation befo…
Browse files Browse the repository at this point in the history
…reSave trigger (#8162)
  • Loading branch information
dblythy committed Sep 16, 2022
1 parent 5250c07 commit 3c75c2b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
50 changes: 50 additions & 0 deletions spec/ParseInstallation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 3c75c2b

Please sign in to comment.