Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(messaging): cloud function sendFCM feature for messaging testing #8143

Merged
merged 4 commits into from
Nov 16, 2024
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
7 changes: 4 additions & 3 deletions .github/workflows/scripts/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^12.5.0",
"firebase-functions": "^6.0.1"
"firebase-admin": "^13.0.0",
"firebase-functions": "^6.1.0"
},
"devDependencies": {
"firebase-functions-test": "^3.3.0",
"typescript": "^5.6.2"
"firebase-tools": "^13.25.0",
"typescript": "^5.6.3"
},
"private": true
}
1 change: 1 addition & 0 deletions .github/workflows/scripts/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export { testFunctionCustomRegion } from './testFunctionCustomRegion';
export { testFunctionDefaultRegionV2 } from './testFunctionDefaultRegion';
export { testFunctionRemoteConfigUpdateV2 } from './testFunctionRemoteConfigUpdate';
export { fetchAppCheckTokenV2 } from './fetchAppCheckToken';
export { sendFCM } from './sendFCM';
28 changes: 28 additions & 0 deletions .github/workflows/scripts/functions/src/sendFCM.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* Testing tools for invertase/react-native-firebase use only.
*
* Copyright (C) 2018-present Invertase Limited <[email protected]>
*
* See License file for more information.
*/

import * as functions from 'firebase-functions/v2';
import { CallableRequest } from 'firebase-functions/v2/https';

import { getMessaging, TokenMessage } from 'firebase-admin/messaging';

// Note: this will only work in a live environment, not locally via the Firebase emulator.
export const sendFCM = functions.https.onCall(
async (req: CallableRequest<{ message: TokenMessage; delay?: number }>) => {
const { message, delay } = req.data;
return await new Promise(() => {
functions.logger.info('Sleeping this many milliseconds: ' + (delay ?? 0));
setTimeout(async () => {
functions.logger.info('done sleeping');
const result = await getMessaging().send(message);
return { messageId: result };
}, delay ?? 0);
});
},
);
Loading
Loading