Skip to content

Commit 1f11ad5

Browse files
aontasflovilmart
authored andcommitted
chore(PushController): Fix push controller tests. (#3853)
1 parent 67a1da8 commit 1f11ad5

File tree

1 file changed

+94
-19
lines changed

1 file changed

+94
-19
lines changed

spec/PushController.spec.js

Lines changed: 94 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,33 @@ describe('PushController', () => {
220220
}).then(() => {
221221
return pushController.sendPush(payload, {}, config, auth);
222222
}).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) => {
225250
jfail(err);
226251
done();
227252
});
@@ -271,9 +296,29 @@ describe('PushController', () => {
271296
}).then(() => {
272297
return pushController.sendPush(payload, {}, config, auth);
273298
}).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);
277322
done();
278323
});
279324
});
@@ -497,21 +542,37 @@ describe('PushController', () => {
497542

498543
const where = {
499544
'deviceToken': {
500-
'$inQuery': {
501-
'where': {
502-
'deviceType': 'ios'
503-
},
504-
className: '_Installation'
505-
}
545+
'$in': ['device_token_0', 'device_token_1', 'device_token_2']
506546
}
507547
}
508548

509549
var pushController = new PushController();
510550
reconfigureServer({
511551
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);
512564
}).then(() => {
513565
return pushController.sendPush(payload, where, config, auth);
514566
}).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);
515576
done();
516577
}).catch((err) => {
517578
jfail(err);
@@ -541,22 +602,36 @@ describe('PushController', () => {
541602
}
542603

543604
const where = {
544-
'deviceToken': {
545-
'$inQuery': {
546-
'where': {
547-
'deviceType': 'ios'
548-
},
549-
className: '_Installation'
550-
}
551-
}
605+
'deviceType': 'ios'
552606
}
553607

554608
var pushController = new PushController();
555609
reconfigureServer({
556610
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);
557623
}).then(() => {
558624
return pushController.sendPush(payload, where, config, auth)
559625
}).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);
560635
done();
561636
}).catch(() => {
562637
fail('should not fail');

0 commit comments

Comments
 (0)