Merge pull request #1248 from ParsePlatform/flovilmart.incrementBadge
Supports increment as well as Increment
This commit is contained in:
@@ -1,28 +1,32 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
describe('Parse.Push', () => {
|
describe('Parse.Push', () => {
|
||||||
it('should properly send push', (done) => {
|
|
||||||
var pushAdapter = {
|
var setup = function() {
|
||||||
send: function(body, installations) {
|
var pushAdapter = {
|
||||||
var badge = body.data.badge;
|
send: function(body, installations) {
|
||||||
let promises = installations.map((installation) => {
|
var badge = body.data.badge;
|
||||||
if (installation.deviceType == "ios") {
|
let promises = installations.map((installation) => {
|
||||||
expect(installation.badge).toEqual(badge);
|
if (installation.deviceType == "ios") {
|
||||||
expect(installation.originalBadge+1).toEqual(installation.badge);
|
expect(installation.badge).toEqual(badge);
|
||||||
} else {
|
expect(installation.originalBadge+1).toEqual(installation.badge);
|
||||||
expect(installation.badge).toBeUndefined();
|
} else {
|
||||||
}
|
expect(installation.badge).toBeUndefined();
|
||||||
return Promise.resolve({
|
}
|
||||||
err: null,
|
return Promise.resolve({
|
||||||
deviceType: installation.deviceType,
|
err: null,
|
||||||
result: true
|
deviceType: installation.deviceType,
|
||||||
})
|
result: true
|
||||||
});
|
})
|
||||||
return Promise.all(promises)
|
});
|
||||||
},
|
return Promise.all(promises);
|
||||||
getValidPushTypes: function() {
|
},
|
||||||
return ["ios", "android"];
|
getValidPushTypes: function() {
|
||||||
}
|
return ["ios", "android"];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setServerConfiguration({
|
setServerConfiguration({
|
||||||
appId: Parse.applicationId,
|
appId: Parse.applicationId,
|
||||||
masterKey: Parse.masterKey,
|
masterKey: Parse.masterKey,
|
||||||
@@ -31,6 +35,7 @@ describe('Parse.Push', () => {
|
|||||||
adapter: pushAdapter
|
adapter: pushAdapter
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var installations = [];
|
var installations = [];
|
||||||
while(installations.length != 10) {
|
while(installations.length != 10) {
|
||||||
var installation = new Parse.Object("_Installation");
|
var installation = new Parse.Object("_Installation");
|
||||||
@@ -41,21 +46,46 @@ describe('Parse.Push', () => {
|
|||||||
installation.set("deviceType", "ios");
|
installation.set("deviceType", "ios");
|
||||||
installations.push(installation);
|
installations.push(installation);
|
||||||
}
|
}
|
||||||
Parse.Object.saveAll(installations).then(() => {
|
return Parse.Object.saveAll(installations);
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should properly send push', (done) => {
|
||||||
|
return setup().then(() => {
|
||||||
return Parse.Push.send({
|
return Parse.Push.send({
|
||||||
where: {
|
where: {
|
||||||
deviceType: 'ios'
|
deviceType: 'ios'
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
badge: 'Increment',
|
badge: 'Increment',
|
||||||
alert: 'Hello world!'
|
alert: 'Hello world!'
|
||||||
}
|
}
|
||||||
}, {useMasterKey: true});
|
}, {useMasterKey: true})
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
done();
|
done();
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.error(err);
|
console.error();
|
||||||
|
fail('should not fail sending push')
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should properly send push with lowercaseIncrement', (done) => {
|
||||||
|
return setup().then(() => {
|
||||||
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export class PushController extends AdaptableController {
|
|||||||
if (body.data && body.data.badge) {
|
if (body.data && body.data.badge) {
|
||||||
let badge = body.data.badge;
|
let badge = body.data.badge;
|
||||||
let op = {};
|
let op = {};
|
||||||
if (badge == "Increment") {
|
if (typeof badge == 'string' && badge.toLowerCase() === 'increment') {
|
||||||
op = { $inc: { badge: 1 } }
|
op = { $inc: { badge: 1 } }
|
||||||
} else if (Number(badge)) {
|
} else if (Number(badge)) {
|
||||||
op = { $set: { badge: badge } }
|
op = { $set: { badge: badge } }
|
||||||
@@ -97,7 +97,7 @@ export class PushController extends AdaptableController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendToAdapter(body, installations, pushStatus, config) {
|
sendToAdapter(body, installations, pushStatus, config) {
|
||||||
if (body.data && body.data.badge && body.data.badge == "Increment") {
|
if (body.data && body.data.badge && typeof body.data.badge == 'string' && body.data.badge.toLowerCase() == "increment") {
|
||||||
// Collect the badges to reduce the # of calls
|
// Collect the badges to reduce the # of calls
|
||||||
let badgeInstallationsMap = installations.reduce((map, installation) => {
|
let badgeInstallationsMap = installations.reduce((map, installation) => {
|
||||||
let badge = installation.badge;
|
let badge = installation.badge;
|
||||||
|
|||||||
Reference in New Issue
Block a user