Skip to content

Commit 6a98e70

Browse files
committed
Supports increment as well as Increment
1 parent 5923347 commit 6a98e70

File tree

2 files changed

+61
-33
lines changed

2 files changed

+61
-33
lines changed

spec/Parse.Push.spec.js

+60-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+
beforeEach((done) => {
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,
@@ -42,20 +46,44 @@ describe('Parse.Push', () => {
4246
installations.push(installation);
4347
}
4448
Parse.Object.saveAll(installations).then(() => {
45-
return Parse.Push.send({
46-
where: {
47-
deviceType: 'ios'
48-
},
49-
data: {
50-
badge: 'Increment',
51-
alert: 'Hello world!'
52-
}
53-
}, {useMasterKey: true});
49+
done();
5450
})
51+
})
52+
53+
it('should properly send push', (done) => {
54+
return Parse.Push.send({
55+
where: {
56+
deviceType: 'ios'
57+
},
58+
data: {
59+
badge: 'Increment',
60+
alert: 'Hello world!'
61+
}
62+
}, {useMasterKey: true})
63+
.then(() => {
64+
done();
65+
}, (err) => {
66+
console.error();
67+
fail('should not fail sending push')
68+
done();
69+
});
70+
});
71+
72+
it('should properly send push with lowercaseIncrement', (done) => {
73+
return Parse.Push.send({
74+
where: {
75+
deviceType: 'ios'
76+
},
77+
data: {
78+
badge: 'increment',
79+
alert: 'Hello world!'
80+
}
81+
}, {useMasterKey: true})
5582
.then(() => {
5683
done();
5784
}, (err) => {
58-
console.error(err);
85+
console.error();
86+
fail('should not fail sending push')
5987
done();
6088
});
6189
});

src/Controllers/PushController.js

+1-1
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 } }

0 commit comments

Comments
 (0)