From eb35731385aa2c67f9f234bec49a25bd376d49d3 Mon Sep 17 00:00:00 2001 From: Alexander Friedl Date: Sun, 12 Feb 2017 11:24:07 +0100 Subject: [PATCH] Fixed test setup for GCM phonegap option (#31) * Fixed test setup for GCM phonegap option * Added proposed fix for PR31 * fix lint error --- src/sendGCM.js | 4 ++-- test/send/sendGCM.js | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/sendGCM.js b/src/sendGCM.js index be5a8bf..55c5df4 100644 --- a/src/sendGCM.js +++ b/src/sendGCM.js @@ -62,8 +62,8 @@ module.exports = (regIds, data, settings) => { title_loc_key: data.titleLocKey, // Android, iOS title_loc_args: data.titleLocArgs, // Android, iOS }; - let custom = typeof data.custom === 'string' ? { message: data.custom } : {}; + let custom; if (typeof data.custom === 'string') { custom = { message: data.custom, @@ -81,7 +81,7 @@ module.exports = (regIds, data, settings) => { custom.sound = custom.sound || data.sound || undefined; custom.icon = custom.icon || data.icon || undefined; custom.msgcnt = custom.msgcnt || data.badge || undefined; - if (opts.phonegap === true) { + if (opts.phonegap === true && data.contentAvailable) { custom['content-available'] = 1; } diff --git a/test/send/sendGCM.js b/test/send/sendGCM.js index fe7a72b..0426752 100644 --- a/test/send/sendGCM.js +++ b/test/send/sendGCM.js @@ -14,6 +14,7 @@ const data = { title: 'title', body: 'body', sound: 'mySound.aiff', + contentAvailable: true, custom: { sender: 'appfeel-test' }, @@ -134,8 +135,10 @@ describe('push-notifications-gcm', () => { }); describe('send push notifications in phonegap-push compatibility mode', () => { - const push = new PN({ - phonegap: true + const pushPhoneGap = new PN({ + gcm: { + phonegap: true + } }); const test = (err, results, done) => { @@ -166,11 +169,12 @@ describe('push-notifications-gcm', () => { registrationTokens.forEach(regId => expect(regIds).to.include(regId)); expect(retries).to.be.a('number'); expect(message).to.be.instanceOf(gcm.Message); - expect(message).to.not.have.property('params.notification'); + expect(message.notification).to.be.undefined; expect(message).to.have.deep.property('params.data.sender', data.custom.sender); expect(message).to.have.deep.property('params.data.title', data.title); expect(message).to.have.deep.property('params.data.message', data.body); expect(message).to.have.deep.property('params.data.sound', data.sound); + expect(message).to.have.deep.property('params.data.content-available', 1); cb(null, { multicast_id: 'abc', success: registrationTokens.length, @@ -189,15 +193,15 @@ describe('push-notifications-gcm', () => { }); it('all responses should be successful (callback)', (done) => { - pn.send(regIds, data, (err, results) => test(err, results, done)); + pushPhoneGap.send(regIds, data, (err, results) => test(err, results, done)); }); it('all responses should be successful (promise)', (done) => { - pn.send(regIds, data) + pushPhoneGap.send(regIds, data) .then(results => test(null, results, done)) .catch(done); }); - }) + }); { const test = (err, results, done) => {