@@ -322,6 +322,111 @@ describe('APNS', () => {
322322 done ( ) ;
323323 } ) ;
324324
325+ it ( 'generating notification prioritizes header information from notification data' , async ( ) => {
326+ const data = {
327+ 'id' : 'hello' ,
328+ 'requestId' : 'world' ,
329+ 'channelId' : 'foo' ,
330+ 'topic' : 'bundle' ,
331+ 'expiry' : 20 ,
332+ 'collapseId' : 'collapse' ,
333+ 'pushType' : 'alert' ,
334+ 'priority' : 7 ,
335+ } ;
336+ const id = 'foo' ;
337+ const requestId = 'hello' ;
338+ const channelId = 'world' ;
339+ const topic = 'bundleId' ;
340+ const expirationTime = 1454571491354 ;
341+ const collapseId = "collapseIdentifier" ;
342+ const pushType = "background" ;
343+ const priority = 5 ;
344+
345+ const notification = APNS . _generateNotification ( data , { id : id , requestId : requestId , channelId : channelId , topic : topic , expirationTime : expirationTime , collapseId : collapseId , pushType : pushType , priority : priority } ) ;
346+ expect ( notification . id ) . toEqual ( data . id ) ;
347+ expect ( notification . requestId ) . toEqual ( data . requestId ) ;
348+ expect ( notification . channelId ) . toEqual ( data . channelId ) ;
349+ expect ( notification . topic ) . toEqual ( data . topic ) ;
350+ expect ( notification . expiry ) . toEqual ( data . expiry ) ;
351+ expect ( notification . collapseId ) . toEqual ( data . collapseId ) ;
352+ expect ( notification . pushType ) . toEqual ( data . pushType ) ;
353+ expect ( notification . priority ) . toEqual ( data . priority ) ;
354+ expect ( Object . keys ( notification . payload ) . length ) . toBe ( 0 ) ;
355+ } ) ;
356+
357+ it ( 'generating notification does not override default notification info when header info is missing' , async ( ) => {
358+ const data = { } ;
359+ const topic = 'bundleId' ;
360+ const collapseId = "collapseIdentifier" ;
361+ const pushType = "background" ;
362+
363+ const notification = APNS . _generateNotification ( data , { topic : topic , collapseId : collapseId , pushType : pushType } ) ;
364+ expect ( notification . topic ) . toEqual ( topic ) ;
365+ expect ( notification . expiry ) . toEqual ( - 1 ) ;
366+ expect ( notification . collapseId ) . toEqual ( collapseId ) ;
367+ expect ( notification . pushType ) . toEqual ( pushType ) ;
368+ expect ( notification . priority ) . toEqual ( 10 ) ;
369+ } ) ;
370+
371+ it ( 'generating notification updates topic properly' , async ( ) => {
372+ const data = { } ;
373+ const topic = 'bundleId' ;
374+ const pushType = "liveactivity" ;
375+
376+ const notification = APNS . _generateNotification ( data , { topic : topic , pushType : pushType } ) ;
377+ expect ( notification . topic ) . toEqual ( topic + '.push-type.liveactivity' ) ;
378+ expect ( notification . pushType ) . toEqual ( pushType ) ;
379+ } ) ;
380+
381+ it ( 'defaults to original topic' , async ( ) => {
382+ const topic = 'bundleId' ;
383+ const pushType = 'alert' ;
384+ const updatedTopic = APNS . _determineTopic ( topic , pushType ) ;
385+ expect ( updatedTopic ) . toEqual ( topic ) ;
386+ } ) ;
387+
388+ it ( 'updates topic based on location pushType' , async ( ) => {
389+ const topic = 'bundleId' ;
390+ const pushType = 'location' ;
391+ const updatedTopic = APNS . _determineTopic ( topic , pushType ) ;
392+ expect ( updatedTopic ) . toEqual ( topic + '.location-query' ) ;
393+ } ) ;
394+
395+ it ( 'updates topic based on voip pushType' , async ( ) => {
396+ const topic = 'bundleId' ;
397+ const pushType = 'voip' ;
398+ const updatedTopic = APNS . _determineTopic ( topic , pushType ) ;
399+ expect ( updatedTopic ) . toEqual ( topic + '.voip' ) ;
400+ } ) ;
401+
402+ it ( 'updates topic based on complication pushType' , async ( ) => {
403+ const topic = 'bundleId' ;
404+ const pushType = 'complication' ;
405+ const updatedTopic = APNS . _determineTopic ( topic , pushType ) ;
406+ expect ( updatedTopic ) . toEqual ( topic + '.complication' ) ;
407+ } ) ;
408+
409+ it ( 'updates topic based on complication pushType' , async ( ) => {
410+ const topic = 'bundleId' ;
411+ const pushType = 'fileprovider' ;
412+ const updatedTopic = APNS . _determineTopic ( topic , pushType ) ;
413+ expect ( updatedTopic ) . toEqual ( topic + '.pushkit.fileprovider' ) ;
414+ } ) ;
415+
416+ it ( 'updates topic based on liveactivity pushType' , async ( ) => {
417+ const topic = 'bundleId' ;
418+ const pushType = 'liveactivity' ;
419+ const updatedTopic = APNS . _determineTopic ( topic , pushType ) ;
420+ expect ( updatedTopic ) . toEqual ( topic + '.push-type.liveactivity' ) ;
421+ } ) ;
422+
423+ it ( 'updates topic based on pushtotalk pushType' , async ( ) => {
424+ const topic = 'bundleId' ;
425+ const pushType = 'pushtotalk' ;
426+ const updatedTopic = APNS . _determineTopic ( topic , pushType ) ;
427+ expect ( updatedTopic ) . toEqual ( topic + '.voip-ptt' ) ;
428+ } ) ;
429+
325430 it ( 'can choose providers for device with valid appIdentifier' , ( done ) => {
326431 const appIdentifier = 'topic' ;
327432 // Mock providers
0 commit comments