From 26fe52974b92b5c42a98c7f610789011ce4c5304 Mon Sep 17 00:00:00 2001
From: Chad Pavliska <chadpav@gmail.com>
Date: Tue, 13 Aug 2024 07:36:40 -0500
Subject: [PATCH 1/2] Failing test showing that if title and alert properties
 are provided that alert will overwrite title.

---
 spec/FCM.spec.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/spec/FCM.spec.js b/spec/FCM.spec.js
index f86102da..2e53334e 100644
--- a/spec/FCM.spec.js
+++ b/spec/FCM.spec.js
@@ -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);
@@ -159,13 +159,13 @@ describe('FCM', () => {
       });
     });
     fcm.pushType = 'apple';
-    const data = { data: { title: 'title' } };
+    const data = { data: { title: 'title', alert: 'alert' } };
     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"]');

From f51be40891dbe10ed5bc4fbef1a2d8f16677fbd2 Mon Sep 17 00:00:00 2001
From: Chad Pavliska <chadpav@gmail.com>
Date: Tue, 13 Aug 2024 08:18:20 -0500
Subject: [PATCH 2/2] FIX: check if the alert key exists before initializing it
 again

---
 src/FCM.js | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/FCM.js b/src/FCM.js
index b6fc9b17..6c0f1c61 100644
--- a/src/FCM.js
+++ b/src/FCM.js
@@ -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')) {
+          apnsPayload['apns']['payload']['aps']['alert'] = {};
+        }
         apnsPayload['apns']['payload']['aps']['alert']['body'] = coreData.alert;
       }
       break;