@@ -190,9 +190,10 @@ describe('APNS', () => {
190190 } ;
191191 let expirationTime = 1454571491354 ;
192192 let collapseId = "collapseIdentifier" ;
193- let priority = 5 ;
194193
195- let notification = APNS . _generateNotification ( data , { expirationTime : expirationTime , collapseId : collapseId , priority : priority } ) ;
194+ let pushType = "alert" ;
195+ let priority = 5 ;
196+ let notification = APNS . _generateNotification ( data , { expirationTime : expirationTime , collapseId : collapseId , pushType : pushType , priority : priority } ) ;
196197
197198 expect ( notification . aps . alert ) . toEqual ( { body : 'alert' , title : 'title' } ) ;
198199 expect ( notification . aps . badge ) . toEqual ( data . badge ) ;
@@ -207,11 +208,35 @@ describe('APNS', () => {
207208 } ) ;
208209 expect ( notification . expiry ) . toEqual ( Math . round ( expirationTime / 1000 ) ) ;
209210 expect ( notification . collapseId ) . toEqual ( collapseId ) ;
211+ expect ( notification . pushType ) . toEqual ( pushType ) ;
210212 expect ( notification . priority ) . toEqual ( priority ) ;
211213 done ( ) ;
212214 } ) ;
215+
216+ it ( 'sets push type to alert if not defined explicitly' , ( done ) => {
217+ //Mock request data
218+ let data = {
219+ 'alert' : 'alert' ,
220+ 'title' : 'title' ,
221+ 'badge' : 100 ,
222+ 'sound' : 'test' ,
223+ 'content-available' : 1 ,
224+ 'mutable-content' : 1 ,
225+ 'category' : 'INVITE_CATEGORY' ,
226+ 'threadId' : 'a-thread-id' ,
227+ 'key' : 'value' ,
228+ 'keyAgain' : 'valueAgain'
229+ } ;
230+ let expirationTime = 1454571491354 ;
231+ let collapseId = "collapseIdentifier" ;
232+
233+ let notification = APNS . _generateNotification ( data , { expirationTime : expirationTime , collapseId : collapseId } ) ;
234+
235+ expect ( notification . pushType ) . toEqual ( 'alert' ) ;
236+ done ( ) ;
237+ } ) ;
213238
214- it ( 'can generate APNS notification from raw data' , ( done ) => {
239+ it ( 'can generate APNS notification from raw data' , ( done ) => {
215240 //Mock request data
216241 let data = {
217242 'aps' : {
@@ -228,12 +253,14 @@ describe('APNS', () => {
228253 } ;
229254 let expirationTime = 1454571491354 ;
230255 let collapseId = "collapseIdentifier" ;
231- let priority = 5
256+ let pushType = "background" ;
257+ let priority = 5 ;
232258
233- let notification = APNS . _generateNotification ( data , { expirationTime : expirationTime , collapseId : collapseId , priority : priority } ) ;
259+ let notification = APNS . _generateNotification ( data , { expirationTime : expirationTime , collapseId : collapseId , pushType : pushType , priority : priority } ) ;
234260
235261 expect ( notification . expiry ) . toEqual ( Math . round ( expirationTime / 1000 ) ) ;
236262 expect ( notification . collapseId ) . toEqual ( collapseId ) ;
263+ expect ( notification . pushType ) . toEqual ( pushType ) ;
237264 expect ( notification . priority ) . toEqual ( priority ) ;
238265
239266 let stringifiedJSON = notification . compile ( ) ;
@@ -302,8 +329,10 @@ describe('APNS', () => {
302329 // Mock data
303330 let expirationTime = 1454571491354 ;
304331 let collapseId = "collapseIdentifier" ;
332+ let pushType = "alert" ; // or background
305333 let data = {
306334 'collapse_id' : collapseId ,
335+ 'push_type' : pushType ,
307336 'expiration_time' : expirationTime ,
308337 'priority' : 6 ,
309338 'data' : {
@@ -335,7 +364,8 @@ describe('APNS', () => {
335364 let notification = calledArgs [ 0 ] ;
336365 expect ( notification . aps . alert ) . toEqual ( data . data . alert ) ;
337366 expect ( notification . expiry ) . toEqual ( Math . round ( data [ 'expiration_time' ] / 1000 ) ) ;
338- expect ( notification . collapseId ) . toEqual ( data [ 'collapse_id' ] ) ;
367+ expect ( notification . collapseId ) . toEqual ( collapseId ) ;
368+ expect ( notification . pushType ) . toEqual ( pushType ) ;
339369 expect ( notification . priority ) . toEqual ( data [ 'priority' ] ) ;
340370 let apnDevices = calledArgs [ 1 ] ;
341371 expect ( apnDevices . length ) . toEqual ( 4 ) ;
@@ -373,9 +403,11 @@ describe('APNS', () => {
373403 apns . providers = [ provider , providerDev ] ;
374404 // Mock data
375405 let expirationTime = 1454571491354 ;
406+ let pushType = "alert" ; // or background
376407 let collapseId = "collapseIdentifier" ;
377408 let data = {
378409 'collapse_id' : collapseId ,
410+ 'push_type' : pushType ,
379411 'expiration_time' : expirationTime ,
380412 'data' : {
381413 'alert' : 'alert'
@@ -413,6 +445,7 @@ describe('APNS', () => {
413445 expect ( notification . aps . alert ) . toEqual ( data . data . alert ) ;
414446 expect ( notification . expiry ) . toEqual ( Math . round ( data [ 'expiration_time' ] / 1000 ) ) ;
415447 expect ( notification . collapseId ) . toEqual ( data [ 'collapse_id' ] ) ;
448+ expect ( notification . pushType ) . toEqual ( pushType ) ;
416449 let apnDevices = calledArgs [ 1 ] ;
417450 expect ( apnDevices . length ) . toBe ( 3 ) ;
418451
@@ -422,6 +455,7 @@ describe('APNS', () => {
422455 expect ( notification . aps . alert ) . toEqual ( data . data . alert ) ;
423456 expect ( notification . expiry ) . toEqual ( Math . round ( data [ 'expiration_time' ] / 1000 ) ) ;
424457 expect ( notification . collapseId ) . toEqual ( data [ 'collapse_id' ] ) ;
458+ expect ( notification . pushType ) . toEqual ( pushType ) ;
425459 apnDevices = calledArgs [ 1 ] ;
426460 expect ( apnDevices . length ) . toBe ( 2 ) ;
427461 done ( ) ;
0 commit comments