@@ -75,4 +75,68 @@ describe("push-notifications-fcm", () => {
7575 . catch ( done ) ;
7676 } ) ;
7777 } ) ;
78+
79+ describe ( 'send push notifications with custom data' , ( ) => {
80+ const customDataMessage = {
81+ title : 'Notification Title' ,
82+ body : 'Notification Body' ,
83+ custom : {
84+ userId : '12345' ,
85+ actionId : 'action-001' ,
86+ deepLink : 'app://section/item' ,
87+ } ,
88+ } ;
89+
90+ let customDataSendMethod ;
91+
92+ function sendCustomDataMethod ( ) {
93+ return sinon . stub (
94+ fbMessaging . prototype ,
95+ 'sendEachForMulticast' ,
96+ function sendFCMWithCustomData ( firebaseMessage ) {
97+ const { custom } = customDataMessage ;
98+
99+ // Verify custom data is preserved in top-level data field
100+ expect ( firebaseMessage . data ) . to . deep . equal ( custom ) ;
101+
102+ // Verify custom data does NOT pollute the notification
103+ // Note: normalizeDataParams converts all values to strings (FCM requirement)
104+ expect ( firebaseMessage . android . data ) . to . deep . equal ( custom ) ;
105+ expect ( firebaseMessage . android . data ) . to . not . have . property ( 'title' ) ;
106+ expect ( firebaseMessage . android . data ) . to . not . have . property ( 'body' ) ;
107+
108+ // Verify notification has proper fields (separate from data)
109+ expect ( firebaseMessage . android . notification ) . to . include ( {
110+ title : customDataMessage . title ,
111+ body : customDataMessage . body ,
112+ } ) ;
113+
114+ return Promise . resolve ( {
115+ successCount : 1 ,
116+ failureCount : 0 ,
117+ responses : [ { error : null } ] ,
118+ } ) ;
119+ }
120+ ) ;
121+ }
122+
123+ before ( ( ) => {
124+ customDataSendMethod = sendCustomDataMethod ( ) ;
125+ } ) ;
126+
127+ after ( ( ) => {
128+ customDataSendMethod . restore ( ) ;
129+ } ) ;
130+
131+ it ( 'custom data should be preserved and not mixed with notification fields' , ( done ) => {
132+ pn . send ( regIds , customDataMessage )
133+ . then ( ( results ) => {
134+ expect ( results ) . to . be . an ( 'array' ) ;
135+ expect ( results [ 0 ] . method ) . to . equal ( 'fcm' ) ;
136+ expect ( results [ 0 ] . success ) . to . equal ( 1 ) ;
137+ done ( ) ;
138+ } )
139+ . catch ( done ) ;
140+ } ) ;
141+ } ) ;
78142} ) ;
0 commit comments