Skip to content

Commit

Permalink
Forward "contentAvailable" and "urlArgs" to APNS
Browse files Browse the repository at this point in the history
  • Loading branch information
jmah authored and Miroslav Bajtoš committed May 29, 2015
1 parent 08e73ee commit e9022a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/providers/apns.js
Expand Up @@ -97,6 +97,8 @@ ApnsProvider.prototype.pushNotification = function(notification, deviceToken) {
note.sound = notification.sound;
note.alert = notification.alert;
note.category = notification.category;
note.contentAvailable = notification.contentAvailable;
note.urlArgs = notification.urlArgs;
note.payload = {};

Object.keys(notification).forEach(function (key) {
Expand Down
4 changes: 3 additions & 1 deletion models/notification.json
Expand Up @@ -8,6 +8,7 @@
"badge": "number",
"category": "string",
"collapseKey": "string",
"contentAvailable": "boolean",
"created": {
"defaultFn": "now",
"type": "date"
Expand All @@ -26,6 +27,7 @@
"modified": "date",
"scheduledTime": "date",
"sound": "string",
"status": "string"
"status": "string",
"urlArgs": ["string"]
}
}
23 changes: 23 additions & 0 deletions test/apns.provider.test.js
Expand Up @@ -36,6 +36,29 @@ describe('APNS provider', function() {
done();
});

it('passes through special APN parameters', function(done) {
givenProviderWithConfig();

var notification = aNotification({
contentAvailable: true,
category: 'my-category',
urlArgs: ['foo', 'bar'],
arbitrary: 'baz'
});
provider.pushNotification(notification, aDeviceToken);

var apnArgs = mockery.firstPushNotificationArgs();

var note = apnArgs[0];
var payload = note.toJSON();
expect(payload.aps['content-available'], 'aps.content-available').to.equal(1);
expect(payload.aps.category, 'aps.category').to.equal('my-category');
expect(payload.aps['url-args'], 'aps.url-args').to.have.length(2);
expect(payload.arbitrary, 'arbitrary').to.equal('baz');

done();
});

it('raises "devicesGone" event when feedback arrives', function(done) {
givenProviderWithConfig({ apns: { feedbackOptions: {}}});
var eventSpy = sinon.spy();
Expand Down

0 comments on commit e9022a0

Please sign in to comment.