@@ -220,8 +220,33 @@ describe('PushController', () => {
220
220
} ) . then ( ( ) => {
221
221
return pushController . sendPush ( payload , { } , config , auth ) ;
222
222
} ) . then ( ( ) => {
223
- done ( ) ;
224
- } , ( err ) => {
223
+ // Wait so the push is completed.
224
+ return new Promise ( ( resolve ) => { setTimeout ( ( ) => { resolve ( ) ; } , 1000 ) ; } ) ;
225
+ } ) . then ( ( ) => {
226
+ // Check we actually sent 15 pushes.
227
+ const query = new Parse . Query ( '_PushStatus' ) ;
228
+ return query . find ( { useMasterKey : true } )
229
+ } ) . then ( ( results ) => {
230
+ expect ( results . length ) . toBe ( 1 ) ;
231
+ const pushStatus = results [ 0 ] ;
232
+ expect ( pushStatus . get ( 'numSent' ) ) . toBe ( 15 ) ;
233
+ } ) . then ( ( ) => {
234
+ // Check that the installations were actually updated.
235
+ const query = new Parse . Query ( '_Installation' ) ;
236
+ return query . find ( { useMasterKey : true } )
237
+ } ) . then ( ( results ) => {
238
+ expect ( results . length ) . toBe ( 15 ) ;
239
+ for ( var i = 0 ; i < 15 ; i ++ ) {
240
+ const installation = results [ i ] ;
241
+ if ( installation . get ( 'deviceType' ) == 'ios' ) {
242
+ expect ( installation . get ( 'badge' ) ) . toBe ( parseInt ( installation . get ( 'originalBadge' ) ) + 1 ) ;
243
+ } else {
244
+ expect ( installation . get ( 'badge' ) ) . toBe ( undefined ) ;
245
+ expect ( installation . get ( 'originalBadge' ) ) . toBe ( undefined ) ;
246
+ }
247
+ }
248
+ done ( )
249
+ } ) . catch ( ( err ) => {
225
250
jfail ( err ) ;
226
251
done ( ) ;
227
252
} ) ;
@@ -271,9 +296,29 @@ describe('PushController', () => {
271
296
} ) . then ( ( ) => {
272
297
return pushController . sendPush ( payload , { } , config , auth ) ;
273
298
} ) . then ( ( ) => {
274
- done ( ) ;
275
- } , ( ) => {
276
- fail ( "should not fail" ) ;
299
+ // Wait so the push is completed.
300
+ return new Promise ( ( resolve ) => { setTimeout ( ( ) => { resolve ( ) ; } , 1000 ) ; } ) ;
301
+ } ) . then ( ( ) => {
302
+ // Check we actually sent the pushes.
303
+ const query = new Parse . Query ( '_PushStatus' ) ;
304
+ return query . find ( { useMasterKey : true } )
305
+ } ) . then ( ( results ) => {
306
+ expect ( results . length ) . toBe ( 1 ) ;
307
+ const pushStatus = results [ 0 ] ;
308
+ expect ( pushStatus . get ( 'numSent' ) ) . toBe ( 10 ) ;
309
+ } ) . then ( ( ) => {
310
+ // Check that the installations were actually updated.
311
+ const query = new Parse . Query ( '_Installation' ) ;
312
+ return query . find ( { useMasterKey : true } )
313
+ } ) . then ( ( results ) => {
314
+ expect ( results . length ) . toBe ( 10 ) ;
315
+ for ( var i = 0 ; i < 10 ; i ++ ) {
316
+ const installation = results [ i ] ;
317
+ expect ( installation . get ( 'badge' ) ) . toBe ( 1 ) ;
318
+ }
319
+ done ( )
320
+ } ) . catch ( ( err ) => {
321
+ jfail ( err ) ;
277
322
done ( ) ;
278
323
} ) ;
279
324
} ) ;
@@ -497,21 +542,37 @@ describe('PushController', () => {
497
542
498
543
const where = {
499
544
'deviceToken' : {
500
- '$inQuery' : {
501
- 'where' : {
502
- 'deviceType' : 'ios'
503
- } ,
504
- className : '_Installation'
505
- }
545
+ '$in' : [ 'device_token_0' , 'device_token_1' , 'device_token_2' ]
506
546
}
507
547
}
508
548
509
549
var pushController = new PushController ( ) ;
510
550
reconfigureServer ( {
511
551
push : { adapter : pushAdapter }
552
+ } ) . then ( ( ) => {
553
+ var installations = [ ] ;
554
+ while ( installations . length != 5 ) {
555
+ const installation = new Parse . Object ( "_Installation" ) ;
556
+ installation . set ( "installationId" , "installation_" + installations . length ) ;
557
+ installation . set ( "deviceToken" , "device_token_" + installations . length )
558
+ installation . set ( "badge" , installations . length ) ;
559
+ installation . set ( "originalBadge" , installations . length ) ;
560
+ installation . set ( "deviceType" , "ios" ) ;
561
+ installations . push ( installation ) ;
562
+ }
563
+ return Parse . Object . saveAll ( installations ) ;
512
564
} ) . then ( ( ) => {
513
565
return pushController . sendPush ( payload , where , config , auth ) ;
514
566
} ) . then ( ( ) => {
567
+ // Wait so the push is completed.
568
+ return new Promise ( ( resolve ) => { setTimeout ( ( ) => { resolve ( ) ; } , 1000 ) ; } ) ;
569
+ } ) . then ( ( ) => {
570
+ const query = new Parse . Query ( '_PushStatus' ) ;
571
+ return query . find ( { useMasterKey : true } )
572
+ } ) . then ( ( results ) => {
573
+ expect ( results . length ) . toBe ( 1 ) ;
574
+ const pushStatus = results [ 0 ] ;
575
+ expect ( pushStatus . get ( 'numSent' ) ) . toBe ( 3 ) ;
515
576
done ( ) ;
516
577
} ) . catch ( ( err ) => {
517
578
jfail ( err ) ;
@@ -541,22 +602,36 @@ describe('PushController', () => {
541
602
}
542
603
543
604
const where = {
544
- 'deviceToken' : {
545
- '$inQuery' : {
546
- 'where' : {
547
- 'deviceType' : 'ios'
548
- } ,
549
- className : '_Installation'
550
- }
551
- }
605
+ 'deviceType' : 'ios'
552
606
}
553
607
554
608
var pushController = new PushController ( ) ;
555
609
reconfigureServer ( {
556
610
push : { adapter : pushAdapter }
611
+ } ) . then ( ( ) => {
612
+ var installations = [ ] ;
613
+ while ( installations . length != 5 ) {
614
+ const installation = new Parse . Object ( "_Installation" ) ;
615
+ installation . set ( "installationId" , "installation_" + installations . length ) ;
616
+ installation . set ( "deviceToken" , "device_token_" + installations . length )
617
+ installation . set ( "badge" , installations . length ) ;
618
+ installation . set ( "originalBadge" , installations . length ) ;
619
+ installation . set ( "deviceType" , "ios" ) ;
620
+ installations . push ( installation ) ;
621
+ }
622
+ return Parse . Object . saveAll ( installations ) ;
557
623
} ) . then ( ( ) => {
558
624
return pushController . sendPush ( payload , where , config , auth )
559
625
} ) . then ( ( ) => {
626
+ // Wait so the push is completed.
627
+ return new Promise ( ( resolve ) => { setTimeout ( ( ) => { resolve ( ) ; } , 1000 ) ; } ) ;
628
+ } ) . then ( ( ) => {
629
+ const query = new Parse . Query ( '_PushStatus' ) ;
630
+ return query . find ( { useMasterKey : true } )
631
+ } ) . then ( ( results ) => {
632
+ expect ( results . length ) . toBe ( 1 ) ;
633
+ const pushStatus = results [ 0 ] ;
634
+ expect ( pushStatus . get ( 'numSent' ) ) . toBe ( 5 ) ;
560
635
done ( ) ;
561
636
} ) . catch ( ( ) => {
562
637
fail ( 'should not fail' ) ;
0 commit comments