From 23fc92bdfa20b1e308fc0b240edf87af2e71013a Mon Sep 17 00:00:00 2001 From: Anthony Mosca Date: Fri, 15 Sep 2017 17:57:19 +0930 Subject: [PATCH] Ensured that raw aps data is correctly parsed --- spec/APNS.spec.js | 33 +++++++++++++++++++++++++++++++++ src/APNS.js | 3 +++ 2 files changed, 36 insertions(+) diff --git a/spec/APNS.spec.js b/spec/APNS.spec.js index aec489f3..8c369bed 100644 --- a/spec/APNS.spec.js +++ b/spec/APNS.spec.js @@ -188,6 +188,39 @@ describe('APNS', () => { expect(notification.collapseId).toEqual(collapseId); done(); }); + + it('can generate APNS notification from raw data', (done) => { + //Mock request data + let data = { + 'aps': { + 'alert': { + "loc-key" : "GAME_PLAY_REQUEST_FORMAT", + "loc-args" : [ "Jenna", "Frank"] + }, + 'badge': 100, + 'sound': 'test' + }, + 'key': 'value', + 'keyAgain': 'valueAgain' + }; + let expirationTime = 1454571491354; + let collapseId = "collapseIdentifier"; + + let notification = APNS._generateNotification(data, { expirationTime: expirationTime, collapseId: collapseId }); + + expect(notification.expiry).toEqual(expirationTime / 1000); + expect(notification.collapseId).toEqual(collapseId); + + let stringifiedJSON = notification.compile(); + let jsonObject = JSON.parse(stringifiedJSON); + + expect(jsonObject.aps.alert).toEqual({ "loc-key" : "GAME_PLAY_REQUEST_FORMAT", "loc-args" : [ "Jenna", "Frank"] }); + expect(jsonObject.aps.badge).toEqual(100); + expect(jsonObject.aps.sound).toEqual('test'); + expect(jsonObject.key).toEqual('value'); + expect(jsonObject.keyAgain).toEqual('valueAgain'); + done(); + }); it('can choose providers for device with valid appIdentifier', (done) => { let appIdentifier = 'topic'; diff --git a/src/APNS.js b/src/APNS.js index 5fa40bea..07570245 100644 --- a/src/APNS.js +++ b/src/APNS.js @@ -174,6 +174,9 @@ export class APNS { let payload = {}; for (let key in coreData) { switch (key) { + case 'aps': + notification.aps = coreData.aps; + break; case 'alert': notification.setAlert(coreData.alert); break;