@@ -845,6 +845,72 @@ describe('PushController', () => {
845845 fail ( 'should not fail' ) ;
846846 done ( ) ;
847847 } ) ;
848+ } ) ;
848849
850+ it ( 'should mark the _PushStatus as succeeded when audience has no deviceToken' , ( done ) => {
851+ var auth = {
852+ isMaster : true
853+ }
854+ var pushAdapter = {
855+ send : function ( body , installations ) {
856+ const promises = installations . map ( ( device ) => {
857+ if ( ! device . deviceToken ) {
858+ // Simulate error when device token is not set
859+ return Promise . reject ( ) ;
860+ }
861+ return Promise . resolve ( {
862+ transmitted : true ,
863+ device : device ,
864+ } )
865+ } ) ;
866+
867+ return Promise . all ( promises ) ;
868+ } ,
869+ getValidPushTypes : function ( ) {
870+ return [ "ios" ] ;
871+ }
872+ }
873+
874+ var pushController = new PushController ( ) ;
875+ const payload = {
876+ data : {
877+ alert : 'hello' ,
878+ } ,
879+ push_time : new Date ( ) . getTime ( ) / 1000
880+ }
881+
882+ var installations = [ ] ;
883+ while ( installations . length != 5 ) {
884+ const installation = new Parse . Object ( "_Installation" ) ;
885+ installation . set ( "installationId" , "installation_" + installations . length ) ;
886+ installation . set ( "badge" , installations . length ) ;
887+ installation . set ( "originalBadge" , installations . length ) ;
888+ installation . set ( "deviceType" , "ios" ) ;
889+ installations . push ( installation ) ;
890+ }
891+
892+ reconfigureServer ( {
893+ push : { adapter : pushAdapter }
894+ } ) . then ( ( ) => {
895+ var config = new Config ( Parse . applicationId ) ;
896+ return Parse . Object . saveAll ( installations ) . then ( ( ) => {
897+ return pushController . sendPush ( payload , { } , config , auth )
898+ . then ( ( ) => { done . fail ( 'should not success' ) } )
899+ . catch ( ( ) => { } )
900+ } ) . then ( ( ) => new Promise ( resolve => setTimeout ( resolve , 100 ) ) ) ;
901+ } ) . then ( ( ) => {
902+ const query = new Parse . Query ( '_PushStatus' ) ;
903+ return query . find ( { useMasterKey : true } ) . then ( ( results ) => {
904+ expect ( results . length ) . toBe ( 1 ) ;
905+ const pushStatus = results [ 0 ] ;
906+ expect ( pushStatus . get ( 'numSent' ) ) . toBe ( 0 ) ;
907+ expect ( pushStatus . get ( 'status' ) ) . toBe ( 'failed' ) ;
908+ done ( ) ;
909+ } ) ;
910+ } ) . catch ( ( err ) => {
911+ console . error ( err ) ;
912+ fail ( 'should not fail' ) ;
913+ done ( ) ;
914+ } ) ;
849915 } ) ;
850916} ) ;
0 commit comments