11import path from 'path' ;
22import fs from 'fs' ;
33
4- // Mock @expo /config-plugins so we don't need the full Expo runtime.
5- // withDangerousMod and withAndroidManifest just invoke their callbacks
6- // immediately with the config object, simulating what Expo does at prebuild.
74jest . mock ( '@expo/config-plugins' , ( ) => ( {
85 withDangerousMod : ( config : any , [ _platform , callback ] : [ string , Function ] ) =>
96 callback ( config ) ,
@@ -18,10 +15,6 @@ jest.mock('@expo/config-plugins', () => ({
1815
1916import { withAndroidPushNotifications } from '../src/expo-plugins/withAndroidPushNotifications' ;
2017
21- /**
22- * Helper to create a minimal Expo config object that the plugins expect.
23- * Mirrors the shape that Expo passes during prebuild.
24- */
2518function createMockConfig ( packageName ?: string ) {
2619 return {
2720 name : 'TestApp' ,
@@ -91,21 +84,16 @@ describe('withAndroidPushNotifications', () => {
9184
9285 const content = writeFileSyncSpy . mock . calls [ 0 ] [ 1 ] as string ;
9386
94- // Token forwarding
9587 expect ( content ) . toContain (
9688 'IntercomModule.sendTokenToIntercom(application, refreshedToken)'
9789 ) ;
98- // Message filtering
9990 expect ( content ) . toContain (
10091 'IntercomModule.isIntercomPush(remoteMessage)'
10192 ) ;
102- // Intercom message handling
10393 expect ( content ) . toContain (
10494 'IntercomModule.handleRemotePushMessage(application, remoteMessage)'
10595 ) ;
106- // Non-Intercom passthrough
10796 expect ( content ) . toContain ( 'super.onMessageReceived(remoteMessage)' ) ;
108- // Token passthrough
10997 expect ( content ) . toContain ( 'super.onNewToken(refreshedToken)' ) ;
11098 } ) ;
11199
@@ -147,7 +135,8 @@ describe('withAndroidPushNotifications', () => {
147135 } ) ;
148136 expect ( writeFileSyncSpy ) . toHaveBeenCalledWith (
149137 path . join ( expectedDir , 'IntercomFirebaseMessagingService.kt' ) ,
150- expect . any ( String )
138+ expect . any ( String ) ,
139+ 'utf-8'
151140 ) ;
152141 } ) ;
153142 } ) ;
@@ -167,7 +156,7 @@ describe('withAndroidPushNotifications', () => {
167156 expect ( service . $ [ 'android:exported' ] ) . toBe ( 'false' ) ;
168157 } ) ;
169158
170- test ( 'registers MESSAGING_EVENT intent filter' , ( ) => {
159+ test ( 'registers MESSAGING_EVENT intent filter with priority ' , ( ) => {
171160 const config = createMockConfig ( 'com.example.myapp' ) ;
172161 withAndroidPushNotifications ( config as any , { } as any ) ;
173162
@@ -178,12 +167,32 @@ describe('withAndroidPushNotifications', () => {
178167 expect ( action . $ [ 'android:name' ] ) . toBe (
179168 'com.google.firebase.MESSAGING_EVENT'
180169 ) ;
170+ expect ( intentFilter . $ [ 'android:priority' ] ) . toBe ( '10' ) ;
171+ } ) ;
172+
173+ test ( 'preserves existing services when adding Intercom service' , ( ) => {
174+ const config = createMockConfig ( 'com.example.myapp' ) ;
175+
176+ config . modResults . manifest . application [ 0 ] . service . push ( {
177+ $ : {
178+ 'android:name' : '.SomeOtherService' ,
179+ 'android:exported' : 'false' ,
180+ } ,
181+ } as any ) ;
182+
183+ withAndroidPushNotifications ( config as any , { } as any ) ;
184+
185+ const services = config . modResults . manifest . application [ 0 ] . service ;
186+ expect ( services ) . toHaveLength ( 2 ) ;
187+ expect ( services [ 0 ] . $ [ 'android:name' ] ) . toBe ( '.SomeOtherService' ) ;
188+ expect ( services [ 1 ] . $ [ 'android:name' ] ) . toBe (
189+ '.IntercomFirebaseMessagingService'
190+ ) ;
181191 } ) ;
182192
183193 test ( 'does not duplicate service on repeated runs (idempotency)' , ( ) => {
184194 const config = createMockConfig ( 'com.example.myapp' ) ;
185195
186- // Run plugin twice on the same config
187196 withAndroidPushNotifications ( config as any , { } as any ) ;
188197 withAndroidPushNotifications ( config as any , { } as any ) ;
189198
@@ -194,7 +203,7 @@ describe('withAndroidPushNotifications', () => {
194203
195204 describe ( 'error handling' , ( ) => {
196205 test ( 'throws if android.package is not defined' , ( ) => {
197- const config = createMockConfig ( ) ; // no package name
206+ const config = createMockConfig ( ) ;
198207
199208 expect ( ( ) => {
200209 withAndroidPushNotifications ( config as any , { } as any ) ;
0 commit comments