@@ -657,4 +657,80 @@ describe('PushController', () => {
657
657
done ( ) ;
658
658
} ) ;
659
659
} ) ;
660
+
661
+ it ( 'should not enqueue push when device token is not set' , ( done ) => {
662
+ var auth = {
663
+ isMaster : true
664
+ }
665
+ var pushAdapter = {
666
+ send : function ( body , installations ) {
667
+ const promises = installations . map ( ( device ) => {
668
+ if ( ! device . deviceToken ) {
669
+ // Simulate error when device token is not set
670
+ return Promise . reject ( ) ;
671
+ }
672
+ return Promise . resolve ( {
673
+ transmitted : true ,
674
+ device : device ,
675
+ } )
676
+ } ) ;
677
+
678
+ return Promise . all ( promises ) ;
679
+ } ,
680
+ getValidPushTypes : function ( ) {
681
+ return [ "ios" ] ;
682
+ }
683
+ }
684
+
685
+ var pushController = new PushController ( ) ;
686
+ const payload = {
687
+ data : {
688
+ alert : 'hello' ,
689
+ } ,
690
+ push_time : new Date ( ) . getTime ( ) / 1000
691
+ }
692
+
693
+ var installations = [ ] ;
694
+ while ( installations . length != 5 ) {
695
+ const installation = new Parse . Object ( "_Installation" ) ;
696
+ installation . set ( "installationId" , "installation_" + installations . length ) ;
697
+ installation . set ( "deviceToken" , "device_token_" + installations . length )
698
+ installation . set ( "badge" , installations . length ) ;
699
+ installation . set ( "originalBadge" , installations . length ) ;
700
+ installation . set ( "deviceType" , "ios" ) ;
701
+ installations . push ( installation ) ;
702
+ }
703
+
704
+ while ( installations . length != 15 ) {
705
+ const installation = new Parse . Object ( "_Installation" ) ;
706
+ installation . set ( "installationId" , "installation_" + installations . length ) ;
707
+ installation . set ( "badge" , installations . length ) ;
708
+ installation . set ( "originalBadge" , installations . length ) ;
709
+ installation . set ( "deviceType" , "ios" ) ;
710
+ installations . push ( installation ) ;
711
+ }
712
+
713
+ reconfigureServer ( {
714
+ push : { adapter : pushAdapter }
715
+ } ) . then ( ( ) => {
716
+ var config = new Config ( Parse . applicationId ) ;
717
+ return Parse . Object . saveAll ( installations ) . then ( ( ) => {
718
+ return pushController . sendPush ( payload , { } , config , auth ) ;
719
+ } ) . then ( ( ) => new Promise ( resolve => setTimeout ( resolve , 100 ) ) ) ;
720
+ } ) . then ( ( ) => {
721
+ const query = new Parse . Query ( '_PushStatus' ) ;
722
+ return query . find ( { useMasterKey : true } ) . then ( ( results ) => {
723
+ expect ( results . length ) . toBe ( 1 ) ;
724
+ const pushStatus = results [ 0 ] ;
725
+ expect ( pushStatus . get ( 'numSent' ) ) . toBe ( 5 ) ;
726
+ expect ( pushStatus . get ( 'status' ) ) . toBe ( 'succeeded' ) ;
727
+ done ( ) ;
728
+ } ) ;
729
+ } ) . catch ( ( err ) => {
730
+ console . error ( err ) ;
731
+ fail ( 'should not fail' ) ;
732
+ done ( ) ;
733
+ } ) ;
734
+
735
+ } ) ;
660
736
} ) ;
0 commit comments