fix: push notifications badge doesn't update with Installation beforeSave trigger (#8162)
This commit is contained in:
@@ -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: Look at additional tests from installation_collection_test.go:882
|
||||||
// TODO: Do we need to support _tombstone disabling of installations?
|
// TODO: Do we need to support _tombstone disabling of installations?
|
||||||
// TODO: Test deletion, badge increments
|
// TODO: Test deletion, badge increments
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ RestWrite.prototype.validateSchema = function () {
|
|||||||
// Runs any beforeSave triggers against this operation.
|
// Runs any beforeSave triggers against this operation.
|
||||||
// Any change leads to our data being mutated.
|
// Any change leads to our data being mutated.
|
||||||
RestWrite.prototype.runBeforeSaveTrigger = function () {
|
RestWrite.prototype.runBeforeSaveTrigger = function () {
|
||||||
if (this.response) {
|
if (this.response || this.runOptions.many) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1522,7 +1522,7 @@ RestWrite.prototype.runDatabaseOperation = function () {
|
|||||||
|
|
||||||
// Returns nothing - doesn't wait for the trigger.
|
// Returns nothing - doesn't wait for the trigger.
|
||||||
RestWrite.prototype.runAfterSaveTrigger = function () {
|
RestWrite.prototype.runAfterSaveTrigger = function () {
|
||||||
if (!this.response || !this.response.response) {
|
if (!this.response || !this.response.response || this.runOptions.many) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user