Skip to content

Commit

Permalink
Supports increment as well as Increment
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Mar 29, 2016
1 parent 5923347 commit 6a98e70
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
92 changes: 60 additions & 32 deletions spec/Parse.Push.spec.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
'use strict';


describe('Parse.Push', () => {
it('should properly send push', (done) => {
var pushAdapter = {
send: function(body, installations) {
var badge = body.data.badge;
let promises = installations.map((installation) => {
if (installation.deviceType == "ios") {
expect(installation.badge).toEqual(badge);
expect(installation.originalBadge+1).toEqual(installation.badge);
} else {
expect(installation.badge).toBeUndefined();
}
return Promise.resolve({
err: null,
deviceType: installation.deviceType,
result: true
})
});
return Promise.all(promises)
},
getValidPushTypes: function() {
return ["ios", "android"];
}

beforeEach((done) => {
var pushAdapter = {
send: function(body, installations) {
var badge = body.data.badge;
let promises = installations.map((installation) => {
if (installation.deviceType == "ios") {
expect(installation.badge).toEqual(badge);
expect(installation.originalBadge+1).toEqual(installation.badge);
} else {
expect(installation.badge).toBeUndefined();
}
return Promise.resolve({
err: null,
deviceType: installation.deviceType,
result: true
})
});
return Promise.all(promises)
},
getValidPushTypes: function() {
return ["ios", "android"];
}
}

setServerConfiguration({
appId: Parse.applicationId,
masterKey: Parse.masterKey,
Expand All @@ -42,20 +46,44 @@ describe('Parse.Push', () => {
installations.push(installation);
}
Parse.Object.saveAll(installations).then(() => {
return Parse.Push.send({
where: {
deviceType: 'ios'
},
data: {
badge: 'Increment',
alert: 'Hello world!'
}
}, {useMasterKey: true});
done();
})
})

it('should properly send push', (done) => {
return Parse.Push.send({
where: {
deviceType: 'ios'
},
data: {
badge: 'Increment',
alert: 'Hello world!'
}
}, {useMasterKey: true})
.then(() => {
done();
}, (err) => {
console.error();
fail('should not fail sending push')
done();
});
});

it('should properly send push with lowercaseIncrement', (done) => {
return Parse.Push.send({
where: {
deviceType: 'ios'
},
data: {
badge: 'increment',
alert: 'Hello world!'
}
}, {useMasterKey: true})
.then(() => {
done();
}, (err) => {
console.error(err);
console.error();
fail('should not fail sending push')
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class PushController extends AdaptableController {
if (body.data && body.data.badge) {
let badge = body.data.badge;
let op = {};
if (badge == "Increment") {
if (typeof badge == 'string' && badge.toLowerCase() === 'increment') {
op = { $inc: { badge: 1 } }
} else if (Number(badge)) {
op = { $set: { badge: badge } }
Expand Down

0 comments on commit 6a98e70

Please sign in to comment.