Skip to content

Commit

Permalink
clean up GCM refs
Browse files Browse the repository at this point in the history
  • Loading branch information
nsakaimbo committed Aug 22, 2024
1 parent 8887df3 commit 96067c3
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 185 deletions.
14 changes: 1 addition & 13 deletions lib/push-notifications.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

var _sendGCM = _interopRequireDefault(require("./sendGCM"));

var _sendAPN = _interopRequireDefault(require("./sendAPN"));

var _sendFCM = _interopRequireDefault(require("./sendFCM"));
Expand All @@ -25,7 +23,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
class PN {
constructor(options) {
this.setOptions(options);
this.useFcmOrGcmMethod = this.settings.isLegacyGCM ? _constants.GCM_METHOD : _constants.FCM_METHOD;
this.useFcmOrGcmMethod = _constants.FCM_METHOD;
}

setOptions(opts) {
Expand Down Expand Up @@ -108,7 +106,6 @@ class PN {

send(_regIds, data, callback) {
const promises = [];
const regIdsGCM = [];
const regIdsFCM = [];
const regIdsAPN = [];
const regIdsWNS = [];
Expand All @@ -124,8 +121,6 @@ class PN {

if (pushMethod === _constants.WEB_METHOD) {
regIdsWebPush.push(regId);
} else if (pushMethod === _constants.GCM_METHOD) {
regIdsGCM.push(regId);
} else if (pushMethod === _constants.FCM_METHOD) {
regIdsFCM.push(regId);
} else if (pushMethod === _constants.WNS_METHOD) {
Expand All @@ -140,12 +135,6 @@ class PN {
});

try {
// Android GCM / FCM (Android/iOS) Legacy
if (regIdsGCM.length > 0) {
promises.push(this.sendWith(_sendGCM.default, regIdsGCM, data));
} // FCM (Android/iOS)


if (regIdsFCM.length > 0) {
promises.push(this.sendWith(_sendFCM.default, regIdsFCM, data));
} // iOS APN
Expand Down Expand Up @@ -219,6 +208,5 @@ module.exports = PN;
module.exports.WEB = _constants.WEB_METHOD;
module.exports.WNS = _constants.WNS_METHOD;
module.exports.ADM = _constants.ADM_METHOD;
module.exports.GCM = _constants.GCM_METHOD;
module.exports.FCM = _constants.FCM_METHOD;
module.exports.APN = _constants.APN_METHOD;
15 changes: 1 addition & 14 deletions src/push-notifications.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable import/no-import-module-exports */

import sendGCM from './sendGCM';
import APN from './sendAPN';
import sendFCM from './sendFCM';
import sendADM from './sendADM';
Expand All @@ -13,17 +12,14 @@ import {
WEB_METHOD,
WNS_METHOD,
ADM_METHOD,
GCM_METHOD,
APN_METHOD,
FCM_METHOD,
} from './constants';

class PN {
constructor(options) {
this.setOptions(options);
this.useFcmOrGcmMethod = this.settings.isLegacyGCM
? GCM_METHOD
: FCM_METHOD;
this.useFcmOrGcmMethod = FCM_METHOD;
}

setOptions(opts) {
Expand Down Expand Up @@ -90,7 +86,6 @@ class PN {

send(_regIds, data, callback) {
const promises = [];
const regIdsGCM = [];
const regIdsFCM = [];
const regIdsAPN = [];
const regIdsWNS = [];
Expand All @@ -105,8 +100,6 @@ class PN {

if (pushMethod === WEB_METHOD) {
regIdsWebPush.push(regId);
} else if (pushMethod === GCM_METHOD) {
regIdsGCM.push(regId);
} else if (pushMethod === FCM_METHOD) {
regIdsFCM.push(regId);
} else if (pushMethod === WNS_METHOD) {
Expand All @@ -121,11 +114,6 @@ class PN {
});

try {
// Android GCM / FCM (Android/iOS) Legacy
if (regIdsGCM.length > 0) {
promises.push(this.sendWith(sendGCM, regIdsGCM, data));
}

// FCM (Android/iOS)
if (regIdsFCM.length > 0) {
promises.push(this.sendWith(sendFCM, regIdsFCM, data));
Expand Down Expand Up @@ -203,6 +191,5 @@ module.exports = PN;
module.exports.WEB = WEB_METHOD;
module.exports.WNS = WNS_METHOD;
module.exports.ADM = ADM_METHOD;
module.exports.GCM = GCM_METHOD;
module.exports.FCM = FCM_METHOD;
module.exports.APN = APN_METHOD;
24 changes: 0 additions & 24 deletions src/utils/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,6 @@ const containsValidRecipients = R.either(
const propValueToSingletonArray = (propName) =>
R.compose(R.of, R.prop(propName));

const buildGcmNotification = (data) => {
const notification = data.fcm_notification || {
title: data.title,
body: data.body,
icon: data.icon,
image: data.image,
picture: data.picture,
style: data.style,
sound: data.sound,
badge: data.badge,
tag: data.tag,
color: data.color,
click_action: data.clickAction || data.category,
body_loc_key: data.locKey,
body_loc_args: toJSONorUndefined(data.locArgs),
title_loc_key: data.titleLocKey,
title_loc_args: toJSONorUndefined(data.titleLocArgs),
android_channel_id: data.android_channel_id,
notification_count: data.notificationCount || data.badge,
};

return notification;
};

const buildApnsMessage = (data) => {
const message = new ApnsMessage({
retryLimit: data.retries || -1,
Expand Down
2 changes: 0 additions & 2 deletions test/push-notifications/regIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { expect } from 'chai'; // eslint-disable-line import/no-extraneous-dependencies
import sinon from 'sinon'; // eslint-disable-line import/no-extraneous-dependencies
import PN from '../../src';
import sendGCM from '../../src/sendGCM';
import sendADM from '../../src/sendADM';
import sendWNS from '../../src/sendWNS';
import sendWeb from '../../src/sendWeb';
Expand Down Expand Up @@ -53,7 +52,6 @@ describe('push-notifications: call with registration ids for android, ios, windo
case 0:
case 1:
case 2:
expect(method).to.equal(sendGCM);
break;

case 3:
Expand Down
34 changes: 1 addition & 33 deletions test/send/sendADM.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { expect } from 'chai';
import sinon from 'sinon';
import adm from 'node-adm';
import PN from '../../src';
import {
sendOkMethodGCM,
testPushSuccess,
testPushError,
testPushException,
} from '../util';
import { testPushSuccess, testPushError, testPushException } from '../util';

const method = 'adm';
const regIds = [
Expand Down Expand Up @@ -164,31 +159,4 @@ describe('push-notifications-adm', () => {
.catch((err) => testException(err, undefined, done));
});
});

describe('send push notifications using FCM', () => {
const pnGCM = new PN({
isAlwaysUseFCM: true,
isLegacyGCM: true,
});
before(() => {
sendMethod = sendOkMethodGCM(regIds, data);
});

after(() => {
sendMethod.restore();
});

it('all responses should be successful (callback)', (done) => {
pnGCM.send(regIds, data, (err, results) =>
testSuccessGCM(err, results, done)
);
});

it('all responses should be successful (promise)', (done) => {
pnGCM
.send(regIds, data)
.then((results) => testSuccessGCM(null, results, done))
.catch(done);
});
});
});
34 changes: 1 addition & 33 deletions test/send/sendAPN.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import { readFileSync } from 'fs';
import apn from '@parse/node-apn';
import PN from '../../src';
import APN from '../../src/sendAPN';
import {
sendOkMethodGCM,
testPushSuccess,
testPushError,
testPushException,
} from '../util';
import { testPushSuccess, testPushError, testPushException } from '../util';

const { expect } = chai;
chai.use(dirtyChai);
Expand Down Expand Up @@ -756,31 +751,4 @@ describe('push-notifications-apn', () => {
});
});
});

describe('send push notifications successfully using FCM', () => {
const pnGCM = new PN({
isAlwaysUseFCM: true,
isLegacyGCM: true,
});
before(() => {
sendMethod = sendOkMethodGCM(regIds, data);
});

after(() => {
sendMethod.restore();
});

it('all responses should be successful (callback)', (done) => {
pnGCM.send(regIds, data, (err, results) =>
testSuccessGCM(err, results, done)
);
});

it('all responses should be successful (promise)', (done) => {
pnGCM
.send(regIds, data)
.then((results) => testSuccessGCM(null, results, done))
.catch(done);
});
});
});
34 changes: 1 addition & 33 deletions test/send/sendWNS-accessToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { expect } from 'chai';
import sinon from 'sinon';
import wns from 'wns';
import PN from '../../src';
import {
sendOkMethodGCM,
testPushSuccess,
testPushError,
testPushException,
} from '../util';
import { testPushSuccess, testPushError, testPushException } from '../util';

const method = 'wns';
const regIds = [
Expand Down Expand Up @@ -223,31 +218,4 @@ describe('push-notifications-wns-access-token', () => {
.catch((err) => testException(err, undefined, done));
});
});

describe('send push notifications successfully using FCM', () => {
const pnGCM = new PN({
isAlwaysUseFCM: true,
isLegacyGCM: true,
});
before(() => {
sendMethod = sendOkMethodGCM(regIds, data);
});

after(() => {
sendMethod.restore();
});

it('all responses should be successful (callback)', (done) => {
pnGCM.send(regIds, data, (err, results) =>
testSuccessGCM(err, results, done)
);
});

it('all responses should be successful (promise)', (done) => {
pnGCM
.send(regIds, data)
.then((results) => testSuccessGCM(null, results, done))
.catch(done);
});
});
});
34 changes: 1 addition & 33 deletions test/send/sendWNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { expect } from 'chai';
import sinon from 'sinon';
import wns from 'wns';
import PN from '../../src';
import {
sendOkMethodGCM,
testPushSuccess,
testPushError,
testPushException,
} from '../util';
import { testPushSuccess, testPushError, testPushException } from '../util';

const method = 'wns';
const regIds = [
Expand Down Expand Up @@ -260,31 +255,4 @@ describe('push-notifications-wns', () => {
.catch((err) => testException(err, undefined, done));
});
});

describe('send push notifications successfully using FCM', () => {
const pnGCM = new PN({
isAlwaysUseFCM: true,
isLegacyGCM: true,
});
before(() => {
sendMethod = sendOkMethodGCM(regIds, data);
});

after(() => {
sendMethod.restore();
});

it('all responses should be successful (callback)', (done) => {
pnGCM.send(regIds, data, (err, results) =>
testSuccessGCM(err, results, done)
);
});

it('all responses should be successful (promise)', (done) => {
pnGCM
.send(regIds, data)
.then((results) => testSuccessGCM(null, results, done))
.catch(done);
});
});
});

0 comments on commit 96067c3

Please sign in to comment.