Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 64 additions & 0 deletions __tests__/withAndroidPushNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,70 @@ dependencies {

warnSpy.mockRestore();
});

test('detects existing FCM service when action is a single object (not array)', () => {
const config = createMockConfig('com.example.myapp');
const warnSpy = jest.spyOn(console, 'warn').mockImplementation();

config.modResults.manifest.application[0].service.push({
'$': {
'android:name': '.ExistingFcmService',
'android:exported': 'true',
},
'intent-filter': [
{
action: {
$: {
'android:name': 'com.google.firebase.MESSAGING_EVENT',
},
},
},
],
} as any);

withAndroidPushNotifications(config as any, {} as any);

const services = config.modResults.manifest.application[0].service;
expect(services).toHaveLength(1);
expect(services[0].$['android:name']).toBe('.ExistingFcmService');
expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining('existing FirebaseMessagingService')
);

warnSpy.mockRestore();
});

test('detects existing FCM service when intent-filter is a single object (not array)', () => {
const config = createMockConfig('com.example.myapp');
const warnSpy = jest.spyOn(console, 'warn').mockImplementation();

config.modResults.manifest.application[0].service.push({
'$': {
'android:name': '.ExistingFcmService',
'android:exported': 'true',
},
'intent-filter': {
action: [
{
$: {
'android:name': 'com.google.firebase.MESSAGING_EVENT',
},
},
],
},
} as any);

withAndroidPushNotifications(config as any, {} as any);

const services = config.modResults.manifest.application[0].service;
expect(services).toHaveLength(1);
expect(services[0].$['android:name']).toBe('.ExistingFcmService');
expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining('existing FirebaseMessagingService')
);

warnSpy.mockRestore();
});
});

describe('error handling', () => {
Expand Down
18 changes: 11 additions & 7 deletions src/expo-plugins/withAndroidPushNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,17 @@ const registerServiceInManifest: ConfigPlugin<IntercomPluginProps> = (
const hasExistingFcmService = mainApplication.service?.some(
(s) =>
s.$?.['android:name'] !== serviceName &&
s['intent-filter']?.some(
(f: any) =>
f.action?.some(
(a: any) =>
a.$?.['android:name'] === 'com.google.firebase.MESSAGING_EVENT'
)
)
([] as any[])
.concat(s['intent-filter'] ?? [])
.some((f: any) =>
([] as any[])
.concat(f.action ?? [])
.some(
(a: any) =>
a.$?.['android:name'] ===
'com.google.firebase.MESSAGING_EVENT'
)
)
);

if (hasExistingFcmService) {
Expand Down
Loading