File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,39 @@ describe('APNS', () => {
188188 expect ( notification . collapseId ) . toEqual ( collapseId ) ;
189189 done ( ) ;
190190 } ) ;
191+
192+ it ( 'can generate APNS notification from raw data' , ( done ) => {
193+ //Mock request data
194+ let data = {
195+ 'aps' : {
196+ 'alert' : {
197+ "loc-key" : "GAME_PLAY_REQUEST_FORMAT" ,
198+ "loc-args" : [ "Jenna" , "Frank" ]
199+ } ,
200+ 'badge' : 100 ,
201+ 'sound' : 'test'
202+ } ,
203+ 'key' : 'value' ,
204+ 'keyAgain' : 'valueAgain'
205+ } ;
206+ let expirationTime = 1454571491354 ;
207+ let collapseId = "collapseIdentifier" ;
208+
209+ let notification = APNS . _generateNotification ( data , { expirationTime : expirationTime , collapseId : collapseId } ) ;
210+
211+ expect ( notification . expiry ) . toEqual ( expirationTime / 1000 ) ;
212+ expect ( notification . collapseId ) . toEqual ( collapseId ) ;
213+
214+ let stringifiedJSON = notification . compile ( ) ;
215+ let jsonObject = JSON . parse ( stringifiedJSON ) ;
216+
217+ expect ( jsonObject . aps . alert ) . toEqual ( { "loc-key" : "GAME_PLAY_REQUEST_FORMAT" , "loc-args" : [ "Jenna" , "Frank" ] } ) ;
218+ expect ( jsonObject . aps . badge ) . toEqual ( 100 ) ;
219+ expect ( jsonObject . aps . sound ) . toEqual ( 'test' ) ;
220+ expect ( jsonObject . key ) . toEqual ( 'value' ) ;
221+ expect ( jsonObject . keyAgain ) . toEqual ( 'valueAgain' ) ;
222+ done ( ) ;
223+ } ) ;
191224
192225 it ( 'can choose providers for device with valid appIdentifier' , ( done ) => {
193226 let appIdentifier = 'topic' ;
Original file line number Diff line number Diff line change @@ -174,6 +174,9 @@ export class APNS {
174174 let payload = { } ;
175175 for ( let key in coreData ) {
176176 switch ( key ) {
177+ case 'aps' :
178+ notification . aps = coreData . aps ;
179+ break ;
177180 case 'alert' :
178181 notification . setAlert ( coreData . alert ) ;
179182 break ;
You can’t perform that action at this time.
0 commit comments