@@ -238,6 +238,68 @@ describe('PushController', () => {
238
238
239
239
} ) ;
240
240
241
+ it ( 'properly set badges to 1 with complex query #2903 #3022' , ( done ) => {
242
+
243
+ var payload = {
244
+ data : {
245
+ alert : "Hello World!" ,
246
+ badge : 1 ,
247
+ }
248
+ }
249
+ var installations = [ ] ;
250
+ while ( installations . length != 10 ) {
251
+ var installation = new Parse . Object ( "_Installation" ) ;
252
+ installation . set ( "installationId" , "installation_" + installations . length ) ;
253
+ installation . set ( "deviceToken" , "device_token_" + installations . length )
254
+ installation . set ( "badge" , installations . length ) ;
255
+ installation . set ( "originalBadge" , installations . length ) ;
256
+ installation . set ( "deviceType" , "ios" ) ;
257
+ installations . push ( installation ) ;
258
+ }
259
+ let matchedInstallationsCount = 0 ;
260
+ var pushAdapter = {
261
+ send : function ( body , installations ) {
262
+ matchedInstallationsCount += installations . length ;
263
+ var badge = body . data . badge ;
264
+ installations . forEach ( ( installation ) => {
265
+ expect ( installation . badge ) . toEqual ( badge ) ;
266
+ expect ( 1 ) . toEqual ( installation . badge ) ;
267
+ } )
268
+ return successfulTransmissions ( body , installations ) ;
269
+ } ,
270
+ getValidPushTypes : function ( ) {
271
+ return [ "ios" ] ;
272
+ }
273
+ }
274
+
275
+ var config = new Config ( Parse . applicationId ) ;
276
+ var auth = {
277
+ isMaster : true
278
+ }
279
+
280
+ var pushController = new PushController ( pushAdapter , Parse . applicationId , defaultConfiguration . push ) ;
281
+ Parse . Object . saveAll ( installations ) . then ( ( installations ) => {
282
+ let objectIds = installations . map ( installation => {
283
+ return installation . id ;
284
+ } )
285
+ let where = {
286
+ objectId : { '$in' : objectIds . slice ( 0 , 5 ) }
287
+ }
288
+ return pushController . sendPush ( payload , where , config , auth ) ;
289
+ } ) . then ( ( ) => {
290
+ expect ( matchedInstallationsCount ) . toBe ( 5 ) ;
291
+ let query = new Parse . Query ( Parse . Installation ) ;
292
+ query . equalTo ( 'badge' , 1 ) ;
293
+ return query . find ( { useMasterKey : true } ) ;
294
+ } ) . then ( ( installations ) => {
295
+ expect ( installations . length ) . toBe ( 5 ) ;
296
+ done ( ) ;
297
+ } ) . catch ( ( ) => {
298
+ fail ( "should not fail" ) ;
299
+ done ( ) ;
300
+ } ) ;
301
+ } ) ;
302
+
241
303
it ( 'properly creates _PushStatus' , ( done ) => {
242
304
243
305
var installations = [ ] ;
0 commit comments