Skip to content

Commit 4891afb

Browse files
committed
Supports increment as well as Increment
1 parent 5923347 commit 4891afb

File tree

2 files changed

+65
-37
lines changed

2 files changed

+65
-37
lines changed

spec/Parse.Push.spec.js

+61-33
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
'use strict';
2-
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-
}
2+
3+
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();
2513
}
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+
}
25+
}
26+
27+
describe('Parse.Push', () => {
28+
29+
beforeEach((done) => {
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ 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") {
60-
op = { $inc: { badge: 1 } }
61-
} else if (Number(badge)) {
59+
if (Number(badge)) {
6260
op = { $set: { badge: badge } }
63-
} else {
61+
} else if (String(badge) && badge.toLowerCase() === 'increment') {
62+
op = { $inc: { badge: 1 } }
63+
} else else {
6464
throw "Invalid value for badge, expected number or 'Increment'";
6565
}
6666
let updateWhere = deepcopy(where);

0 commit comments

Comments
 (0)