Skip to content

Commit bdc2a82

Browse files
jeffjenflovilmart
authored andcommitted
Classify installation with pushType and failback with deviceType (#31)
1 parent 1858398 commit bdc2a82

File tree

2 files changed

+84
-3
lines changed

2 files changed

+84
-3
lines changed

spec/ParsePushAdapter.spec.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,87 @@ describe('ParsePushAdapter', () => {
141141
done();
142142
});
143143

144+
it('can send push notifications by pushType and failback by deviceType', (done) => {
145+
var parsePushAdapter = new ParsePushAdapter();
146+
// Mock android ios senders
147+
var androidSender = {
148+
send: jasmine.createSpy('send')
149+
};
150+
var iosSender = {
151+
send: jasmine.createSpy('send')
152+
};
153+
var senderMap = {
154+
ios: iosSender,
155+
android: androidSender
156+
};
157+
parsePushAdapter.senderMap = senderMap;
158+
// Mock installations
159+
var installations = [
160+
{
161+
deviceType: 'android',
162+
deviceToken: 'androidToken'
163+
},
164+
{
165+
deviceType: 'android',
166+
pushType: 'gcm',
167+
deviceToken: 'androidToken'
168+
},
169+
{
170+
deviceType: 'android',
171+
pushType: 'ppns',
172+
deviceToken: 'androidToken'
173+
},
174+
{
175+
deviceType: 'android',
176+
pushType: 'none',
177+
deviceToken: 'androidToken'
178+
},
179+
{
180+
deviceType: 'ios',
181+
deviceToken: 'iosToken'
182+
},
183+
{
184+
deviceType: 'ios',
185+
pushType: 'ios',
186+
deviceToken: 'iosToken'
187+
},
188+
{
189+
deviceType: 'win',
190+
deviceToken: 'winToken'
191+
},
192+
{
193+
deviceType: 'win',
194+
deviceToken: 'winToken'
195+
},
196+
{
197+
deviceType: 'android',
198+
deviceToken: undefined
199+
}
200+
];
201+
var data = {};
202+
203+
parsePushAdapter.send(data, installations);
204+
// Check android sender
205+
expect(androidSender.send).toHaveBeenCalled();
206+
var args = androidSender.send.calls.first().args;
207+
expect(args[0]).toEqual(data);
208+
expect(args[1]).toEqual([
209+
makeDevice('androidToken'),
210+
makeDevice('androidToken'),
211+
makeDevice('androidToken'),
212+
makeDevice('androidToken')
213+
]);
214+
// Check ios sender
215+
expect(iosSender.send).toHaveBeenCalled();
216+
args = iosSender.send.calls.first().args;
217+
expect(args[0]).toEqual(data);
218+
expect(args[1]).toEqual([
219+
makeDevice('iosToken'),
220+
makeDevice('iosToken')
221+
]);
222+
done();
223+
});
224+
144225
it('reports properly results', (done) => {
145226
var pushConfig = {
146227
android: {

src/PushAdapterUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export function classifyInstallations(installations, validPushTypes) {
1717
if (!installation.deviceToken) {
1818
continue;
1919
}
20-
let pushType = installation.deviceType;
21-
if (deviceMap[pushType]) {
22-
deviceMap[pushType].push({
20+
let devices = deviceMap[installation.pushType] || deviceMap[installation.deviceType] || null;
21+
if (Array.isArray(devices)) {
22+
devices.push({
2323
deviceToken: installation.deviceToken,
2424
appIdentifier: installation.appIdentifier
2525
});

0 commit comments

Comments
 (0)