Skip to content

Commit

Permalink
Let multiple installations be updates if no critical values are set (p…
Browse files Browse the repository at this point in the history
…arse-community#3040)

* Let multiple installations be updates if no critical values are set

* nits
  • Loading branch information
flovilmart authored and Jcarlosjunior committed Dec 13, 2016
1 parent 9e3045d commit 81040f7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
62 changes: 62 additions & 0 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,68 @@ describe('PushController', () => {

});

it('properly set badges to 1 with complex query #2903 #3022', (done) => {

var payload = {
data: {
alert: "Hello World!",
badge: 1,
}
}
var installations = [];
while(installations.length != 10) {
var installation = new Parse.Object("_Installation");
installation.set("installationId", "installation_"+installations.length);
installation.set("deviceToken","device_token_"+installations.length)
installation.set("badge", installations.length);
installation.set("originalBadge", installations.length);
installation.set("deviceType", "ios");
installations.push(installation);
}
let matchedInstallationsCount = 0;
var pushAdapter = {
send: function(body, installations) {
matchedInstallationsCount += installations.length;
var badge = body.data.badge;
installations.forEach((installation) => {
expect(installation.badge).toEqual(badge);
expect(1).toEqual(installation.badge);
})
return successfulTransmissions(body, installations);
},
getValidPushTypes: function() {
return ["ios"];
}
}

var config = new Config(Parse.applicationId);
var auth = {
isMaster: true
}

var pushController = new PushController(pushAdapter, Parse.applicationId, defaultConfiguration.push);
Parse.Object.saveAll(installations).then((installations) => {
let objectIds = installations.map(installation => {
return installation.id;
})
let where = {
objectId: {'$in': objectIds.slice(0, 5)}
}
return pushController.sendPush(payload, where, config, auth);
}).then(() => {
expect(matchedInstallationsCount).toBe(5);
let query = new Parse.Query(Parse.Installation);
query.equalTo('badge', 1);
return query.find({useMasterKey: true});
}).then((installations) => {
expect(installations.length).toBe(5);
done();
}).catch(() => {
fail("should not fail");
done();
});
});

it('properly creates _PushStatus', (done) => {

var installations = [];
Expand Down
1 change: 1 addition & 0 deletions src/LiveQuery/ParseCloudCodePublisher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ParsePubSub } from './ParsePubSub';
import Parse from 'parse/node';
import logger from '../logger';

class ParseCloudCodePublisher {
Expand Down
6 changes: 6 additions & 0 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,12 @@ RestWrite.prototype.handleInstallation = function() {
installationId = installationId.toLowerCase();
}

// Updating _Installation but not updating anything critical
if (this.query && !this.data.deviceToken
&& !installationId && !this.data.deviceType) {
return;
}

var promise = Promise.resolve();

var idMatch; // Will be a match on either objectId or installationId
Expand Down

0 comments on commit 81040f7

Please sign in to comment.