Skip to content

Commit

Permalink
Fixed test setup for GCM phonegap option (#31)
Browse files Browse the repository at this point in the history
* Fixed test setup for GCM phonegap option

* Added proposed fix for PR31

* fix lint error
  • Loading branch information
alex-friedl authored and appfeel committed Feb 12, 2017
1 parent ebc9e89 commit eb35731
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/sendGCM.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down
16 changes: 10 additions & 6 deletions test/send/sendGCM.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const data = {
title: 'title',
body: 'body',
sound: 'mySound.aiff',
contentAvailable: true,
custom: {
sender: 'appfeel-test'
},
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down

0 comments on commit eb35731

Please sign in to comment.