Skip to content

Commit c8b7909

Browse files
committed
test(messaging): sendFCM function that reflects a TokenMessage
- requires a TokenMessage, and just sends the Message to the device addressed by the token in the message - optionally can have a delay so you can put a test app in background or kill it or similar after calling the API For security purposes: - Tested this with an incorrect google-services.json / plist and the function call simply fails - Tested this with an incorrect package name and the function all also simply fails - Tested it with a correct package name and you can send on android, but on iOS there is still a lot of Apple developer account / app work to do, so that fails.
1 parent f32414d commit c8b7909

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

.github/workflows/scripts/functions/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export { testFunctionCustomRegion } from './testFunctionCustomRegion';
2323
export { testFunctionDefaultRegionV2 } from './testFunctionDefaultRegion';
2424
export { testFunctionRemoteConfigUpdateV2 } from './testFunctionRemoteConfigUpdate';
2525
export { fetchAppCheckTokenV2 } from './fetchAppCheckToken';
26+
export { sendFCM } from './sendFCM';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
*
3+
* Testing tools for invertase/react-native-firebase use only.
4+
*
5+
* Copyright (C) 2018-present Invertase Limited <[email protected]>
6+
*
7+
* See License file for more information.
8+
*/
9+
10+
import * as functions from 'firebase-functions/v2';
11+
import { CallableRequest } from 'firebase-functions/v2/https';
12+
13+
import { getMessaging, TokenMessage } from 'firebase-admin/messaging';
14+
15+
// Note: this will only work in a live environment, not locally via the Firebase emulator.
16+
export const sendFCM = functions.https.onCall(
17+
async (req: CallableRequest<{ message: TokenMessage; delay?: number }>) => {
18+
const { message, delay } = req.data;
19+
return await new Promise(() => {
20+
functions.logger.info('Sleeping this many milliseconds: ' + (delay ?? 0));
21+
setTimeout(async () => {
22+
functions.logger.info('done sleeping');
23+
const result = await getMessaging().send(message);
24+
return { messageId: result };
25+
}, delay ?? 0);
26+
});
27+
},
28+
);

0 commit comments

Comments
 (0)