Skip to content

reports all sending error for mis-configurations #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions spec/ParsePushAdapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,65 @@ describe('ParsePushAdapter', () => {
done();
});

it('reports properly results', (done) => {
var pushConfig = {
android: {
senderId: 'senderId',
apiKey: 'apiKey'
},
ios: [
{
cert: 'cert.cer',
key: 'key.pem',
production: false,
bundleId: 'bundleId'
}
]
};
var installations = [
{
deviceType: 'android',
deviceToken: 'androidToken'
},
{
deviceType: 'ios',
deviceToken: 'c5ee8fae0a1c',
appIdentifier: 'anotherBundle'
},
{
deviceType: 'ios',
deviceToken: 'c5ee8fae0a1c5805e731cf15496d5b2b3f9b9c577353d3239429d3faaee01c79',
appIdentifier: 'anotherBundle'
},
{
deviceType: 'win',
deviceToken: 'winToken'
},
{
deviceType: 'android',
deviceToken: undefined
}
];

var parsePushAdapter = new ParsePushAdapter(pushConfig);
parsePushAdapter.send({data: {alert: 'some'}}, installations).then((results) => {
expect(Array.isArray(results)).toBe(true);

// 2x iOS, 1x android
expect(results.length).toBe(3);
results.forEach((result) => {
expect(result.transmitted).toBe(false);
expect(typeof result.device).toBe('object');
expect(typeof result.device.deviceType).toBe('string');
expect(typeof result.device.deviceToken).toBe('string');
})
done();
}).catch((err) => {
fail('Should not fail');
done();
})
});

function makeDevice(deviceToken, appIdentifier) {
return {
deviceToken: deviceToken,
Expand Down
17 changes: 14 additions & 3 deletions src/APNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ function APNS(args) {
device.callback({
notification: notification,
transmitted: true,
device: device
device: {
deviceType: 'ios',
deviceToken: device.token.toString('hex')
}
});
}
console.log('APNS Connection %d Notification transmitted to %s', conn.index, device.token.toString('hex'));
Expand Down Expand Up @@ -105,6 +108,10 @@ APNS.prototype.send = function(data, devices) {
if (qualifiedConnIndexs.length == 0) {
return Promise.resolve({
transmitted: false,
device: {
deviceToken: device.deviceToken,
deviceType: 'ios'
},
result: {error: 'No connection available'}
});
}
Expand Down Expand Up @@ -148,9 +155,13 @@ function handleTransmissionError(conns, errCode, notification, apnDevice) {
if (newConnIndex < 0 || newConnIndex >= conns.length) {
if (apnDevice.callback) {
apnDevice.callback({
response: {error: `APNS can not find vaild connection for ${apnDevice.token}`, code: errCode},
response: {error: `APNS can not find vaild connection for ${apnDevice.token.toString('hex')}`, code: errCode},
status: errCode,
transmitted: false
transmitted: false,
device: {
deviceType: 'ios',
deviceToken: apnDevice.token.toString('hex')
}
});
}
return;
Expand Down
1 change: 1 addition & 0 deletions src/GCM.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ GCM.prototype.send = function(data, devices) {
let promise = promises[index];
let result = results ? results[index] : undefined;
let device = devicesMap[token];
device.deviceType = 'android';
let resolution = {
device,
multicast_id,
Expand Down
19 changes: 13 additions & 6 deletions src/ParsePushAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,24 @@ export class ParsePushAdapter {
let sendPromises = [];
for (let pushType in deviceMap) {
let sender = this.senderMap[pushType];
let devices = deviceMap[pushType];
if (!sender) {
sendPromises.push(Promise.resolve({
transmitted: false,
response: {'error': `Can not find sender for push type ${pushType}, ${data}`}
}))
let results = devices.map((device) => {
return Promise.resolve({
device,
transmitted: false,
response: {'error': `Can not find sender for push type ${pushType}, ${data}`}
})
});
sendPromises.push(Promise.all(results));
} else {
let devices = deviceMap[pushType];
sendPromises.push(sender.send(data, devices));
}
}
return Parse.Promise.when(sendPromises);
return Promise.all(sendPromises).then((promises) => {
// flatten all
return [].concat.apply([], promises);
})
}
}
export default ParsePushAdapter;
Expand Down