Skip to content

Commit 337d3c2

Browse files
committed
Merge pull request #1248 from ParsePlatform/flovilmart.incrementBadge
Supports increment as well as Increment
2 parents ef08dcf + cb4b036 commit 337d3c2

File tree

2 files changed

+64
-34
lines changed

2 files changed

+64
-34
lines changed

spec/Parse.Push.spec.js

+62-32
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
'use strict';
2+
3+
24
describe('Parse.Push', () => {
3-
it('should properly send push', (done) => {
4-
var pushAdapter = {
5-
send: function(body, installations) {
6-
var badge = body.data.badge;
7-
let promises = installations.map((installation) => {
8-
if (installation.deviceType == "ios") {
9-
expect(installation.badge).toEqual(badge);
10-
expect(installation.originalBadge+1).toEqual(installation.badge);
11-
} else {
12-
expect(installation.badge).toBeUndefined();
13-
}
14-
return Promise.resolve({
15-
err: null,
16-
deviceType: installation.deviceType,
17-
result: true
18-
})
19-
});
20-
return Promise.all(promises)
21-
},
22-
getValidPushTypes: function() {
23-
return ["ios", "android"];
24-
}
5+
6+
var setup = function() {
7+
var pushAdapter = {
8+
send: function(body, installations) {
9+
var badge = body.data.badge;
10+
let promises = installations.map((installation) => {
11+
if (installation.deviceType == "ios") {
12+
expect(installation.badge).toEqual(badge);
13+
expect(installation.originalBadge+1).toEqual(installation.badge);
14+
} else {
15+
expect(installation.badge).toBeUndefined();
16+
}
17+
return Promise.resolve({
18+
err: null,
19+
deviceType: installation.deviceType,
20+
result: true
21+
})
22+
});
23+
return Promise.all(promises);
24+
},
25+
getValidPushTypes: function() {
26+
return ["ios", "android"];
2527
}
28+
}
29+
2630
setServerConfiguration({
2731
appId: Parse.applicationId,
2832
masterKey: Parse.masterKey,
@@ -31,6 +35,7 @@ describe('Parse.Push', () => {
3135
adapter: pushAdapter
3236
}
3337
});
38+
3439
var installations = [];
3540
while(installations.length != 10) {
3641
var installation = new Parse.Object("_Installation");
@@ -41,21 +46,46 @@ describe('Parse.Push', () => {
4146
installation.set("deviceType", "ios");
4247
installations.push(installation);
4348
}
44-
Parse.Object.saveAll(installations).then(() => {
49+
return Parse.Object.saveAll(installations);
50+
}
51+
52+
it('should properly send push', (done) => {
53+
return setup().then(() => {
4554
return Parse.Push.send({
46-
where: {
47-
deviceType: 'ios'
48-
},
49-
data: {
50-
badge: 'Increment',
51-
alert: 'Hello world!'
52-
}
53-
}, {useMasterKey: true});
55+
where: {
56+
deviceType: 'ios'
57+
},
58+
data: {
59+
badge: 'Increment',
60+
alert: 'Hello world!'
61+
}
62+
}, {useMasterKey: true})
5463
})
5564
.then(() => {
5665
done();
5766
}, (err) => {
58-
console.error(err);
67+
console.error();
68+
fail('should not fail sending push')
69+
done();
70+
});
71+
});
72+
73+
it('should properly send push with lowercaseIncrement', (done) => {
74+
return setup().then(() => {
75+
return Parse.Push.send({
76+
where: {
77+
deviceType: 'ios'
78+
},
79+
data: {
80+
badge: 'increment',
81+
alert: 'Hello world!'
82+
}
83+
}, {useMasterKey: true})
84+
}).then(() => {
85+
done();
86+
}, (err) => {
87+
console.error();
88+
fail('should not fail sending push')
5989
done();
6090
});
6191
});

src/Controllers/PushController.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class PushController extends AdaptableController {
5656
if (body.data && body.data.badge) {
5757
let badge = body.data.badge;
5858
let op = {};
59-
if (badge == "Increment") {
59+
if (typeof badge == 'string' && badge.toLowerCase() === 'increment') {
6060
op = { $inc: { badge: 1 } }
6161
} else if (Number(badge)) {
6262
op = { $set: { badge: badge } }
@@ -97,7 +97,7 @@ export class PushController extends AdaptableController {
9797
}
9898

9999
sendToAdapter(body, installations, pushStatus, config) {
100-
if (body.data && body.data.badge && body.data.badge == "Increment") {
100+
if (body.data && body.data.badge && typeof body.data.badge == 'string' && body.data.badge.toLowerCase() == "increment") {
101101
// Collect the badges to reduce the # of calls
102102
let badgeInstallationsMap = installations.reduce((map, installation) => {
103103
let badge = installation.badge;

0 commit comments

Comments
 (0)