Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions spec/FCM.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('FCM', () => {
}]]);
});

it('can send successful FCM apple request with title', async () => {
it('can send successful FCM apple request with title and alert', async () => {
const spyVerbose = spyOn(log, 'verbose').and.callFake(() => {});
const spyInfo = spyOn(log, 'info').and.callFake(() => {});
const fcm = new FCM(testArgs);
Expand All @@ -159,13 +159,13 @@ describe('FCM', () => {
});
});
fcm.pushType = 'apple';
const data = { data: { title: 'title' } };
const data = { data: { title: 'title', alert: 'alert' } };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a new test to test specifically what this fix is about, rather than modifying an existing test?

const devices = [{ deviceToken: 'token' }];
const response = await fcm.send(data, devices);
expect(fcm.sender.sendEachForMulticast).toHaveBeenCalled();
const args = fcm.sender.sendEachForMulticast.calls.first().args;
expect(args.length).toEqual(1);
expect(args[0].apns.payload).toEqual({ aps: { alert: { title: 'title' } } });
expect(args[0].apns.payload).toEqual({ aps: { alert: { title: 'title', body: 'alert' } } });
expect(args[0].apns.headers).toEqual({ 'apns-push-type': 'alert' });
expect(args[0].tokens).toEqual(['token']);
expect(spyVerbose).toHaveBeenCalledWith('parse-server-push-adapter FCM', 'tokens with successful pushes: ["token"]');
Expand Down
6 changes: 4 additions & 2 deletions src/FCM.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ function _APNSToFCMPayload(requestData) {
// compatible with how the APNS.js + node-apn work
apnsPayload['apns']['payload']['aps']['alert'] = coreData.alert;
} else {
// When we receive a value, prepare `alert` dictionary
// When we receive a value, prepare `alert` dictionary if needed
// and set its `body` property
apnsPayload['apns']['payload']['aps']['alert'] = {};
if (!apnsPayload['apns']['payload']['aps'].hasOwnProperty('alert')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this is a replication of the logic under caes 'title':, correct? However, I find it strange to use hasOwnProperty for this, did you just use this from the other case?

apnsPayload['apns']['payload']['aps']['alert'] = {};
}
apnsPayload['apns']['payload']['aps']['alert']['body'] = coreData.alert;
}
break;
Expand Down