-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Jules writes unit test for sendMessage #9001
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
base: master
Are you sure you want to change the base?
Conversation
Adds unit tests for the `sendFcmMessage` function in `src/messaging/sendMessage.ts`. The new tests cover: - Sending a message with a token - Sending a message with a topic - Handling cases where neither a token nor a topic is provided - Handling API errors Also includes a bug fix in `sendFcmMessage` to correctly handle the API response and error conditions.
Adds unit tests for the `sendFcmMessage` function in `src/messaging/sendMessage.ts`. The new tests cover: - Sending a message with a token - Sending a message with a topic - Handling cases where neither a token nor a topic is provided - Handling API errors Also includes a bug fix in `sendFcmMessage` to correctly handle the API response and error conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @joehan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces comprehensive unit tests for the sendFcmMessage
utility, enhancing the reliability and maintainability of the messaging module. It also includes minor refactorings to the sendFcmMessage
function itself, improving its input validation and ensuring correct parsing of API responses. These changes collectively contribute to a more robust and well-tested messaging system.
Highlights
- New Unit Tests for
sendFcmMessage
: A new test file,src/messaging/sendMessage.spec.ts
, has been added to introduce unit tests for thesendFcmMessage
function. These tests ensure the function behaves as expected under various conditions, including successful message delivery and error scenarios. - Improved Input Validation in
sendFcmMessage
: The validation logic withinsendFcmMessage
has been improved by moving the check for the presence of either a token or a topic to the very beginning of the function. This ensures that invalid calls are caught earlier, preventing unnecessary processing. - Accurate Message ID Extraction: The
sendFcmMessage
function now correctly parses the response from the messaging API, specifically extracting the message ID from thename
property of the response body. This ensures the function returns the expected message identifier upon successful API calls.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a comprehensive set of unit tests for the sendFcmMessage
function, which is a great addition for ensuring its reliability. The tests cover success scenarios with both tokens and topics, as well as important failure cases like missing parameters and API errors. The accompanying refactoring in sendMessage.ts
to use a guard clause and provide a more specific type for the API response improves the code's correctness and readability. I've identified a minor issue in one of the new tests and a suggestion to improve test code maintainability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One open comment.
method: "POST", | ||
path: `/projects/${projectId}/messages:send`, | ||
body: JSON.stringify(messageData), | ||
timeout: TIMEOUT, | ||
}); | ||
return res.body; | ||
return res.body.name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is correct. I think it should be res.body.message.name
.. right?
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#Message
Description
From Jules - unit tests for sendMessage.ts
I verified the changes to the API as well - this was just incorrect before (https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#Message) but it never came up becuase we just send and forget in the one place we use this.