Verify pushes are sent to the expected number of installations (#3418)

This commit is contained in:
Ricardo Matsui
2017-01-28 11:10:21 -08:00
committed by Arthur Cinader
parent ea45f69af6
commit d67be492f5

View File

@@ -10,10 +10,14 @@ const delayPromise = (delay) => {
describe('Parse.Push', () => { describe('Parse.Push', () => {
var setup = function() { var setup = function() {
var sendToInstallationSpy = jasmine.createSpy();
var pushAdapter = { var pushAdapter = {
send: function(body, installations) { send: function(body, installations) {
var badge = body.data.badge; var badge = body.data.badge;
const promises = installations.map((installation) => { const promises = installations.map((installation) => {
sendToInstallationSpy(installation);
if (installation.deviceType == "ios") { if (installation.deviceType == "ios") {
expect(installation.badge).toEqual(badge); expect(installation.badge).toEqual(badge);
expect(installation.originalBadge + 1).toEqual(installation.badge); expect(installation.originalBadge + 1).toEqual(installation.badge);
@@ -53,13 +57,21 @@ describe('Parse.Push', () => {
installations.push(installation); installations.push(installation);
} }
return Parse.Object.saveAll(installations); return Parse.Object.saveAll(installations);
}).catch((err) => { })
.then(() => {
return {
sendToInstallationSpy,
};
})
.catch((err) => {
console.error(err); console.error(err);
throw err;
}) })
} }
it('should properly send push', (done) => { it('should properly send push', (done) => {
return setup().then(() => { return setup().then(({ sendToInstallationSpy }) => {
return Parse.Push.send({ return Parse.Push.send({
where: { where: {
deviceType: 'ios' deviceType: 'ios'
@@ -69,10 +81,13 @@ describe('Parse.Push', () => {
alert: 'Hello world!' alert: 'Hello world!'
} }
}, {useMasterKey: true}) }, {useMasterKey: true})
.then(() => {
return delayPromise(500);
})
.then(() => {
expect(sendToInstallationSpy.calls.count()).toEqual(10);
})
}).then(() => { }).then(() => {
return delayPromise(500);
})
.then(() => {
done(); done();
}).catch((err) => { }).catch((err) => {
jfail(err); jfail(err);