@@ -290,6 +290,18 @@ describe('APNS', () => {
290290 {
291291 deviceToken : '112233' ,
292292 appIdentifier : 'bundleId'
293+ } ,
294+ {
295+ deviceToken : '112234' ,
296+ appIdentifier : 'bundleId'
297+ } ,
298+ {
299+ deviceToken : '112235' ,
300+ appIdentifier : 'bundleId'
301+ } ,
302+ {
303+ deviceToken : '112236' ,
304+ appIdentifier : 'bundleId'
293305 }
294306 ] ;
295307
@@ -299,9 +311,94 @@ describe('APNS', () => {
299311 var notification = args [ 0 ] ;
300312 expect ( notification . alert ) . toEqual ( data . data . alert ) ;
301313 expect ( notification . expiry ) . toEqual ( data [ 'expiration_time' ] / 1000 ) ;
302- var apnDevice = args [ 1 ]
303- expect ( apnDevice . connIndex ) . toEqual ( 0 ) ;
304- expect ( apnDevice . appIdentifier ) . toEqual ( 'bundleId' ) ;
314+ var apnDevices = args [ 1 ] ;
315+ apnDevices . forEach ( ( apnDevice ) => {
316+ expect ( apnDevice . connIndex ) . toEqual ( 0 ) ;
317+ expect ( apnDevice . appIdentifier ) . toEqual ( 'bundleId' ) ;
318+ } )
319+ done ( ) ;
320+ } ) ;
321+
322+ it ( 'can send APNS notification to multiple bundles' , ( done ) => {
323+ var args = [ {
324+ cert : 'prodCert.pem' ,
325+ key : 'prodKey.pem' ,
326+ production : true ,
327+ bundleId : 'bundleId'
328+ } , {
329+ cert : 'devCert.pem' ,
330+ key : 'devKey.pem' ,
331+ production : false ,
332+ bundleId : 'bundleId.dev'
333+ } ] ;
334+
335+ var apns = new APNS ( args ) ;
336+ var conn = {
337+ pushNotification : jasmine . createSpy ( 'send' ) ,
338+ bundleId : 'bundleId'
339+ } ;
340+ var conndev = {
341+ pushNotification : jasmine . createSpy ( 'send' ) ,
342+ bundleId : 'bundleId.dev'
343+ } ;
344+ apns . conns = [ conn , conndev ] ;
345+ // Mock data
346+ var expirationTime = 1454571491354
347+ var data = {
348+ 'expiration_time' : expirationTime ,
349+ 'data' : {
350+ 'alert' : 'alert'
351+ }
352+ }
353+ // Mock devices
354+ var devices = [
355+ {
356+ deviceToken : '112233' ,
357+ appIdentifier : 'bundleId'
358+ } ,
359+ {
360+ deviceToken : '112234' ,
361+ appIdentifier : 'bundleId'
362+ } ,
363+ {
364+ deviceToken : '112235' ,
365+ appIdentifier : 'bundleId'
366+ } ,
367+ {
368+ deviceToken : '112235' ,
369+ appIdentifier : 'bundleId.dev'
370+ } ,
371+ {
372+ deviceToken : '112236' ,
373+ appIdentifier : 'bundleId.dev'
374+ }
375+ ] ;
376+
377+ var promise = apns . send ( data , devices ) ;
378+
379+ expect ( conn . pushNotification ) . toHaveBeenCalled ( ) ;
380+ var args = conn . pushNotification . calls . first ( ) . args ;
381+ var notification = args [ 0 ] ;
382+ expect ( notification . alert ) . toEqual ( data . data . alert ) ;
383+ expect ( notification . expiry ) . toEqual ( data [ 'expiration_time' ] / 1000 ) ;
384+ var apnDevices = args [ 1 ] ;
385+ expect ( apnDevices . length ) . toBe ( 3 ) ;
386+ apnDevices . forEach ( ( apnDevice ) => {
387+ expect ( apnDevice . connIndex ) . toEqual ( 0 ) ;
388+ expect ( apnDevice . appIdentifier ) . toEqual ( 'bundleId' ) ;
389+ } )
390+
391+ expect ( conndev . pushNotification ) . toHaveBeenCalled ( ) ;
392+ args = conndev . pushNotification . calls . first ( ) . args ;
393+ notification = args [ 0 ] ;
394+ expect ( notification . alert ) . toEqual ( data . data . alert ) ;
395+ expect ( notification . expiry ) . toEqual ( data [ 'expiration_time' ] / 1000 ) ;
396+ apnDevices = args [ 1 ] ;
397+ expect ( apnDevices . length ) . toBe ( 2 ) ;
398+ apnDevices . forEach ( ( apnDevice ) => {
399+ expect ( apnDevice . connIndex ) . toEqual ( 1 ) ;
400+ expect ( apnDevice . appIdentifier ) . toEqual ( 'bundleId.dev' ) ;
401+ } ) ;
305402 done ( ) ;
306403 } ) ;
307404} ) ;
0 commit comments