@@ -372,6 +372,67 @@ describe('APNS', () => {
372
372
done ( ) ;
373
373
} ) ;
374
374
375
+ it ( 'can send APNS notification headers in data' , ( done ) => {
376
+ let args = {
377
+ cert : new Buffer ( 'testCert' ) ,
378
+ key : new Buffer ( 'testKey' ) ,
379
+ production : true ,
380
+ topic : 'topic'
381
+ } ;
382
+ let apns = new APNS ( args ) ;
383
+ let provider = apns . providers [ 0 ] ;
384
+ spyOn ( provider , 'send' ) . and . callFake ( ( notification , devices ) => {
385
+ return Promise . resolve ( {
386
+ sent : devices ,
387
+ failed : [ ]
388
+ } )
389
+ } ) ;
390
+ // Mock data
391
+ let expirationTime = 1454571491354 ;
392
+ let collapseId = "collapseIdentifier" ;
393
+ let pushType = "alert" ; // or background
394
+ let data = {
395
+ 'expiration_time' : expirationTime ,
396
+ 'data' : {
397
+ 'alert' : 'alert' ,
398
+ 'collapse_id' : collapseId ,
399
+ 'push_type' : pushType ,
400
+ 'priority' : 6 ,
401
+ }
402
+ } ;
403
+ // Mock devices
404
+ let mockedDevices = [
405
+ {
406
+ deviceToken : '112233' ,
407
+ appIdentifier : 'topic'
408
+ } ,
409
+ {
410
+ deviceToken : '112234' ,
411
+ appIdentifier : 'topic'
412
+ } ,
413
+ {
414
+ deviceToken : '112235' ,
415
+ appIdentifier : 'topic'
416
+ } ,
417
+ {
418
+ deviceToken : '112236' ,
419
+ appIdentifier : 'topic'
420
+ }
421
+ ] ;
422
+ let promise = apns . send ( data , mockedDevices ) ;
423
+ expect ( provider . send ) . toHaveBeenCalled ( ) ;
424
+ let calledArgs = provider . send . calls . first ( ) . args ;
425
+ let notification = calledArgs [ 0 ] ;
426
+ expect ( notification . aps . alert ) . toEqual ( data . data . alert ) ;
427
+ expect ( notification . expiry ) . toEqual ( Math . round ( data [ 'expiration_time' ] / 1000 ) ) ;
428
+ expect ( notification . collapseId ) . toEqual ( collapseId ) ;
429
+ expect ( notification . pushType ) . toEqual ( pushType ) ;
430
+ expect ( notification . priority ) . toEqual ( 6 ) ;
431
+ let apnDevices = calledArgs [ 1 ] ;
432
+ expect ( apnDevices . length ) . toEqual ( 4 ) ;
433
+ done ( ) ;
434
+ } ) ;
435
+
375
436
it ( 'can send APNS notification to multiple bundles' , ( done ) => {
376
437
let args = [ {
377
438
cert : new Buffer ( 'testCert' ) ,
0 commit comments