Skip to content

Commit 3c75c2b

Browse files
authored
fix: push notifications badge doesn't update with Installation beforeSave trigger (parse-community#8162)
1 parent 5250c07 commit 3c75c2b

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

spec/ParseInstallation.spec.js

+50
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,56 @@ describe('Installations', () => {
12391239
});
12401240
});
12411241

1242+
it('can use push with beforeSave', async () => {
1243+
const input = {
1244+
deviceToken: '11433856eed2f1285fb3aa11136718c1198ed5647875096952c66bf8cb976306',
1245+
deviceType: 'ios',
1246+
};
1247+
await rest.create(config, auth.nobody(config), '_Installation', input)
1248+
const functions = {
1249+
beforeSave() {},
1250+
afterSave() {}
1251+
}
1252+
spyOn(functions, 'beforeSave').and.callThrough();
1253+
spyOn(functions, 'afterSave').and.callThrough();
1254+
Parse.Cloud.beforeSave(Parse.Installation, functions.beforeSave);
1255+
Parse.Cloud.afterSave(Parse.Installation, functions.afterSave);
1256+
await Parse.Push.send({
1257+
where: {
1258+
deviceType: 'ios',
1259+
},
1260+
data: {
1261+
badge: 'increment',
1262+
alert: 'Hello world!',
1263+
},
1264+
});
1265+
1266+
await Parse.Push.send({
1267+
where: {
1268+
deviceType: 'ios',
1269+
},
1270+
data: {
1271+
badge: 'increment',
1272+
alert: 'Hello world!',
1273+
},
1274+
});
1275+
1276+
await Parse.Push.send({
1277+
where: {
1278+
deviceType: 'ios',
1279+
},
1280+
data: {
1281+
badge: 'increment',
1282+
alert: 'Hello world!',
1283+
},
1284+
});
1285+
await new Promise(resolve => setTimeout(resolve, 1000));
1286+
const installation = await new Parse.Query(Parse.Installation).first({useMasterKey: true});
1287+
expect(installation.get('badge')).toEqual(3);
1288+
expect(functions.beforeSave).not.toHaveBeenCalled();
1289+
expect(functions.afterSave).not.toHaveBeenCalled();
1290+
});
1291+
12421292
// TODO: Look at additional tests from installation_collection_test.go:882
12431293
// TODO: Do we need to support _tombstone disabling of installations?
12441294
// TODO: Test deletion, badge increments

src/RestWrite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ RestWrite.prototype.validateSchema = function () {
217217
// Runs any beforeSave triggers against this operation.
218218
// Any change leads to our data being mutated.
219219
RestWrite.prototype.runBeforeSaveTrigger = function () {
220-
if (this.response) {
220+
if (this.response || this.runOptions.many) {
221221
return;
222222
}
223223

@@ -1522,7 +1522,7 @@ RestWrite.prototype.runDatabaseOperation = function () {
15221522

15231523
// Returns nothing - doesn't wait for the trigger.
15241524
RestWrite.prototype.runAfterSaveTrigger = function () {
1525-
if (!this.response || !this.response.response) {
1525+
if (!this.response || !this.response.response || this.runOptions.many) {
15261526
return;
15271527
}
15281528

0 commit comments

Comments
 (0)