@@ -190,9 +190,10 @@ describe('APNS', () => {
190
190
} ;
191
191
let expirationTime = 1454571491354 ;
192
192
let collapseId = "collapseIdentifier" ;
193
- let priority = 5 ;
194
193
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 } ) ;
196
197
197
198
expect ( notification . aps . alert ) . toEqual ( { body : 'alert' , title : 'title' } ) ;
198
199
expect ( notification . aps . badge ) . toEqual ( data . badge ) ;
@@ -207,11 +208,35 @@ describe('APNS', () => {
207
208
} ) ;
208
209
expect ( notification . expiry ) . toEqual ( Math . round ( expirationTime / 1000 ) ) ;
209
210
expect ( notification . collapseId ) . toEqual ( collapseId ) ;
211
+ expect ( notification . pushType ) . toEqual ( pushType ) ;
210
212
expect ( notification . priority ) . toEqual ( priority ) ;
211
213
done ( ) ;
212
214
} ) ;
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
+ } ) ;
213
238
214
- it ( 'can generate APNS notification from raw data' , ( done ) => {
239
+ it ( 'can generate APNS notification from raw data' , ( done ) => {
215
240
//Mock request data
216
241
let data = {
217
242
'aps' : {
@@ -228,12 +253,14 @@ describe('APNS', () => {
228
253
} ;
229
254
let expirationTime = 1454571491354 ;
230
255
let collapseId = "collapseIdentifier" ;
231
- let priority = 5
256
+ let pushType = "background" ;
257
+ let priority = 5 ;
232
258
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 } ) ;
234
260
235
261
expect ( notification . expiry ) . toEqual ( Math . round ( expirationTime / 1000 ) ) ;
236
262
expect ( notification . collapseId ) . toEqual ( collapseId ) ;
263
+ expect ( notification . pushType ) . toEqual ( pushType ) ;
237
264
expect ( notification . priority ) . toEqual ( priority ) ;
238
265
239
266
let stringifiedJSON = notification . compile ( ) ;
@@ -302,8 +329,10 @@ describe('APNS', () => {
302
329
// Mock data
303
330
let expirationTime = 1454571491354 ;
304
331
let collapseId = "collapseIdentifier" ;
332
+ let pushType = "alert" ; // or background
305
333
let data = {
306
334
'collapse_id' : collapseId ,
335
+ 'push_type' : pushType ,
307
336
'expiration_time' : expirationTime ,
308
337
'priority' : 6 ,
309
338
'data' : {
@@ -335,7 +364,8 @@ describe('APNS', () => {
335
364
let notification = calledArgs [ 0 ] ;
336
365
expect ( notification . aps . alert ) . toEqual ( data . data . alert ) ;
337
366
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 ) ;
339
369
expect ( notification . priority ) . toEqual ( data [ 'priority' ] ) ;
340
370
let apnDevices = calledArgs [ 1 ] ;
341
371
expect ( apnDevices . length ) . toEqual ( 4 ) ;
@@ -373,9 +403,11 @@ describe('APNS', () => {
373
403
apns . providers = [ provider , providerDev ] ;
374
404
// Mock data
375
405
let expirationTime = 1454571491354 ;
406
+ let pushType = "alert" ; // or background
376
407
let collapseId = "collapseIdentifier" ;
377
408
let data = {
378
409
'collapse_id' : collapseId ,
410
+ 'push_type' : pushType ,
379
411
'expiration_time' : expirationTime ,
380
412
'data' : {
381
413
'alert' : 'alert'
@@ -413,6 +445,7 @@ describe('APNS', () => {
413
445
expect ( notification . aps . alert ) . toEqual ( data . data . alert ) ;
414
446
expect ( notification . expiry ) . toEqual ( Math . round ( data [ 'expiration_time' ] / 1000 ) ) ;
415
447
expect ( notification . collapseId ) . toEqual ( data [ 'collapse_id' ] ) ;
448
+ expect ( notification . pushType ) . toEqual ( pushType ) ;
416
449
let apnDevices = calledArgs [ 1 ] ;
417
450
expect ( apnDevices . length ) . toBe ( 3 ) ;
418
451
@@ -422,6 +455,7 @@ describe('APNS', () => {
422
455
expect ( notification . aps . alert ) . toEqual ( data . data . alert ) ;
423
456
expect ( notification . expiry ) . toEqual ( Math . round ( data [ 'expiration_time' ] / 1000 ) ) ;
424
457
expect ( notification . collapseId ) . toEqual ( data [ 'collapse_id' ] ) ;
458
+ expect ( notification . pushType ) . toEqual ( pushType ) ;
425
459
apnDevices = calledArgs [ 1 ] ;
426
460
expect ( apnDevices . length ) . toBe ( 2 ) ;
427
461
done ( ) ;
0 commit comments