chore(PushController): Fix push controller tests. (#3853)
This commit is contained in:
committed by
Florent Vilmart
parent
67a1da8f9f
commit
1f11ad5d74
@@ -220,8 +220,33 @@ describe('PushController', () => {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
return pushController.sendPush(payload, {}, config, auth);
|
return pushController.sendPush(payload, {}, config, auth);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
done();
|
// Wait so the push is completed.
|
||||||
}, (err) => {
|
return new Promise((resolve) => { setTimeout(() => { resolve(); }, 1000); });
|
||||||
|
}).then(() => {
|
||||||
|
// Check we actually sent 15 pushes.
|
||||||
|
const query = new Parse.Query('_PushStatus');
|
||||||
|
return query.find({ useMasterKey: true })
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results.length).toBe(1);
|
||||||
|
const pushStatus = results[0];
|
||||||
|
expect(pushStatus.get('numSent')).toBe(15);
|
||||||
|
}).then(() => {
|
||||||
|
// Check that the installations were actually updated.
|
||||||
|
const query = new Parse.Query('_Installation');
|
||||||
|
return query.find({ useMasterKey: true })
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results.length).toBe(15);
|
||||||
|
for (var i = 0; i < 15; i++) {
|
||||||
|
const installation = results[i];
|
||||||
|
if (installation.get('deviceType') == 'ios') {
|
||||||
|
expect(installation.get('badge')).toBe(parseInt(installation.get('originalBadge')) + 1);
|
||||||
|
} else {
|
||||||
|
expect(installation.get('badge')).toBe(undefined);
|
||||||
|
expect(installation.get('originalBadge')).toBe(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
done()
|
||||||
|
}).catch((err) => {
|
||||||
jfail(err);
|
jfail(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -271,9 +296,29 @@ describe('PushController', () => {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
return pushController.sendPush(payload, {}, config, auth);
|
return pushController.sendPush(payload, {}, config, auth);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
done();
|
// Wait so the push is completed.
|
||||||
}, () => {
|
return new Promise((resolve) => { setTimeout(() => { resolve(); }, 1000); });
|
||||||
fail("should not fail");
|
}).then(() => {
|
||||||
|
// Check we actually sent the pushes.
|
||||||
|
const query = new Parse.Query('_PushStatus');
|
||||||
|
return query.find({ useMasterKey: true })
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results.length).toBe(1);
|
||||||
|
const pushStatus = results[0];
|
||||||
|
expect(pushStatus.get('numSent')).toBe(10);
|
||||||
|
}).then(() => {
|
||||||
|
// Check that the installations were actually updated.
|
||||||
|
const query = new Parse.Query('_Installation');
|
||||||
|
return query.find({ useMasterKey: true })
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results.length).toBe(10);
|
||||||
|
for (var i = 0; i < 10; i++) {
|
||||||
|
const installation = results[i];
|
||||||
|
expect(installation.get('badge')).toBe(1);
|
||||||
|
}
|
||||||
|
done()
|
||||||
|
}).catch((err) => {
|
||||||
|
jfail(err);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -497,21 +542,37 @@ describe('PushController', () => {
|
|||||||
|
|
||||||
const where = {
|
const where = {
|
||||||
'deviceToken': {
|
'deviceToken': {
|
||||||
'$inQuery': {
|
'$in': ['device_token_0', 'device_token_1', 'device_token_2']
|
||||||
'where': {
|
|
||||||
'deviceType': 'ios'
|
|
||||||
},
|
|
||||||
className: '_Installation'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pushController = new PushController();
|
var pushController = new PushController();
|
||||||
reconfigureServer({
|
reconfigureServer({
|
||||||
push: { adapter: pushAdapter }
|
push: { adapter: pushAdapter }
|
||||||
|
}).then(() => {
|
||||||
|
var installations = [];
|
||||||
|
while (installations.length != 5) {
|
||||||
|
const installation = new Parse.Object("_Installation");
|
||||||
|
installation.set("installationId", "installation_" + installations.length);
|
||||||
|
installation.set("deviceToken", "device_token_" + installations.length)
|
||||||
|
installation.set("badge", installations.length);
|
||||||
|
installation.set("originalBadge", installations.length);
|
||||||
|
installation.set("deviceType", "ios");
|
||||||
|
installations.push(installation);
|
||||||
|
}
|
||||||
|
return Parse.Object.saveAll(installations);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return pushController.sendPush(payload, where, config, auth);
|
return pushController.sendPush(payload, where, config, auth);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
// Wait so the push is completed.
|
||||||
|
return new Promise((resolve) => { setTimeout(() => { resolve(); }, 1000); });
|
||||||
|
}).then(() => {
|
||||||
|
const query = new Parse.Query('_PushStatus');
|
||||||
|
return query.find({ useMasterKey: true })
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results.length).toBe(1);
|
||||||
|
const pushStatus = results[0];
|
||||||
|
expect(pushStatus.get('numSent')).toBe(3);
|
||||||
done();
|
done();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
jfail(err);
|
jfail(err);
|
||||||
@@ -541,22 +602,36 @@ describe('PushController', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const where = {
|
const where = {
|
||||||
'deviceToken': {
|
'deviceType': 'ios'
|
||||||
'$inQuery': {
|
|
||||||
'where': {
|
|
||||||
'deviceType': 'ios'
|
|
||||||
},
|
|
||||||
className: '_Installation'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pushController = new PushController();
|
var pushController = new PushController();
|
||||||
reconfigureServer({
|
reconfigureServer({
|
||||||
push: { adapter: pushAdapter }
|
push: { adapter: pushAdapter }
|
||||||
|
}).then(() => {
|
||||||
|
var installations = [];
|
||||||
|
while (installations.length != 5) {
|
||||||
|
const installation = new Parse.Object("_Installation");
|
||||||
|
installation.set("installationId", "installation_" + installations.length);
|
||||||
|
installation.set("deviceToken", "device_token_" + installations.length)
|
||||||
|
installation.set("badge", installations.length);
|
||||||
|
installation.set("originalBadge", installations.length);
|
||||||
|
installation.set("deviceType", "ios");
|
||||||
|
installations.push(installation);
|
||||||
|
}
|
||||||
|
return Parse.Object.saveAll(installations);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return pushController.sendPush(payload, where, config, auth)
|
return pushController.sendPush(payload, where, config, auth)
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
// Wait so the push is completed.
|
||||||
|
return new Promise((resolve) => { setTimeout(() => { resolve(); }, 1000); });
|
||||||
|
}).then(() => {
|
||||||
|
const query = new Parse.Query('_PushStatus');
|
||||||
|
return query.find({ useMasterKey: true })
|
||||||
|
}).then((results) => {
|
||||||
|
expect(results.length).toBe(1);
|
||||||
|
const pushStatus = results[0];
|
||||||
|
expect(pushStatus.get('numSent')).toBe(5);
|
||||||
done();
|
done();
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
fail('should not fail');
|
fail('should not fail');
|
||||||
|
|||||||
Reference in New Issue
Block a user