-
Notifications
You must be signed in to change notification settings - Fork 1k
Tests for app-* commands #8909
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?
Tests for app-* commands #8909
Conversation
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 significantly enhances the test coverage for various apps-*
commands within the codebase. The primary intent is to improve the reliability and maintainability of these command-line functionalities by adding robust unit tests, as part of an experiment to use Gemini for test generation. No functional changes are introduced; the focus is purely on ensuring the correctness of existing behavior through automated testing.
Highlights
- New Test Coverage: Introduced comprehensive unit tests for several
apps-*
commands, includingapps:android:sha:create
,apps:android:sha:delete
,apps:android:sha:list
,apps:create
,apps:list
, andapps:sdkconfig
. - Improved Testability: Exported several internal utility functions (
getCertHashType
,logCertificatesList
,logCertificatesCount
,logPostAppCreationInformation
,logAppsList
,logAppCount
) from their respective command files to enable direct unit testing. - Type Definition Refinement: Adjusted the
AppAndroidShaData
interface insrc/management/apps.ts
to generalize thecertType
property from a specificSHA_1
enum value to the broaderShaCertificateType
, accommodating different SHA certificate types.
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 or fill out our survey to provide feedback.
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 adds tests for the app-*
commands. I've left suggestions to make the tests more robust by verifying that stubbed functions are called with the correct arguments and asserting that the correct messages are logged for logging functions. I also suggested a change to the type definition for certType
in src/management/apps.ts
.
await command.runner()("test-app-id", shaHash, {}); | ||
|
||
expect(needProjectIdStub).to.have.been.calledOnce; | ||
expect(createAppAndroidShaStub).to.have.been.calledOnce; |
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.
This test checks that createAppAndroidShaStub
is called, but it could be more robust by also verifying that it's called with the correct arguments. This ensures the command is correctly interpreting its inputs and passing them to the management API.
expect(createAppAndroidShaStub).to.have.been.calledOnceWith("test-project-id", "test-app-id", {
shaHash: shaHash,
certType: ShaCertificateType.SHA_1
});
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.
Can we address this ^?
await command.runner()("test-app-id", "test-sha-id", {}); | ||
|
||
expect(needProjectIdStub).to.have.been.calledOnce; | ||
expect(deleteAppAndroidShaStub).to.have.been.calledOnce; |
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.
To make this test more specific, consider asserting that deleteAppAndroidShaStub
is called with the expected arguments (projectId
, appId
, and shaId
). This will ensure the command is correctly parsing and passing its arguments.
expect(deleteAppAndroidShaStub).to.have.been.calledOnce; | |
expect(deleteAppAndroidShaStub).to.have.been.calledOnceWith("test-project-id", "test-app-id", "test-sha-id"); |
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.
^ can we address this as well?
promiseWithSpinnerStub.resolves(certificates); | ||
|
||
await command.runner()("test-app-id", {}); | ||
|
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.
This test stubs promiseWithSpinner
directly, which prevents the actual logic inside the action (the call to listAppAndroidSha
) from being executed. A more effective test would be to let promiseWithSpinner
execute (using callThrough
) and stub listAppAndroidSha
instead. This would allow you to verify that listAppAndroidSha
is called with the correct arguments, which is the primary responsibility of this command's action.
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.
I agree with this!
it('should display "No SHA certificate hashes found." if no certificates exist', async () => { | ||
promiseWithSpinnerStub.resolves([]); | ||
|
||
await command.runner()("test-app-id", {}); | ||
|
||
// No assertion needed here, we are just checking that it does not throw. | ||
}); |
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.
This test only checks that the command doesn't throw an error when no certificates are found. A stronger assertion would be to verify that the correct message is logged to the user. You can achieve this by spying on logger.info
and checking that it's called with a message including "No SHA certificate hashes found.".
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.
Can we address this?
platform: AppPlatform.WEB, | ||
displayName: "test-display-name", | ||
}; | ||
logPostAppCreationInformation(appMetadata, AppPlatform.WEB); |
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.
it('should display "No apps found." if no apps exist', async () => { | ||
listFirebaseAppsStub.resolves([]); | ||
getAppPlatformStub.returns(AppPlatform.ANY); | ||
|
||
await command.runner()(undefined, {}); | ||
|
||
// No assertion needed here, we are just checking that it does not throw. | ||
}); |
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.
describe("logAppCount", () => { | ||
it("should print the total number of apps", () => { | ||
logAppCount(5); | ||
// No assertion needed here, we are just checking that it does not throw. | ||
}); | ||
|
||
it("should not print if count is 0", () => { | ||
logAppCount(0); | ||
// No assertion needed here, we are just checking that it does not throw. | ||
}); | ||
}); |
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.
|
||
expect(promiseWithSpinnerStub).to.have.been.calledOnce; | ||
const spinnerText = promiseWithSpinnerStub.getCall(0).args[1]; | ||
expect(spinnerText).to.include("Preparing the list"); |
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.
Can we also check that the logger logged the list that you stubbed above?
}); | ||
|
||
it("should prompt for platform if not provided in interactive mode", async () => { | ||
getAppPlatformStub.withArgs("").returns(AppPlatform.ANY); |
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.
Does this need to be here?
src/commands/apps-sdkconfig.spec.ts
Outdated
}); | ||
|
||
it("should get config for the only app when no app id is provided", async () => { | ||
needProjectIdStub.returns("test-project-id"); |
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.
This one line appears in most of the tests. Should it be moved into the beforeEach
block?
* Fix apptesting enablement (#8905) * Fix an issue with apptesting enablement Co-authored-by: Joe Hanley <joehanley@google.com> * Fix issue where login didnt work as expected on studio (#8914) * Fix issue where login didnt work as expected on studio * Update src/commands/login.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * 14.11.2 * [firebase-release] Removed change log and reset repo after 14.11.2 release * Enable FDC API in `firebase init dataconnect` for Spark projects (#8927) * feat: address pr comments on app-* commands * Fetch active Firebase Project from Studio Workspace when running in Studio (#8904) * Disable broken VSCode integration tests (#8934) * Add userinfo.email scope when in studio (#8935) * Add userinfo.email scope when in studio * Update src/requireAuth.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update src/requireAuth.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * feat: Display Firestore database edition (#8926) * feat: Display Firestore database edition Adds the 'Edition' to the output of the `firestore:databases:get` command. The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table. The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`. * feat: Display Firestore database edition Adds the 'Edition' to the output of the `firestore:databases:get` command. The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table. The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`. * feat: Display Firestore database edition Adds the 'Edition' to the output of the `firestore:databases:get` command. The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table. The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`. Also refactors the tests for `prettyPrintDatabase` to improve readability and maintainability. * feat: Display Firestore database edition Adds the 'Edition' to the output of the `firestore:databases:get` command. The `Database` resource in the Firestore API now includes a `databaseEdition` field. This change updates the `DatabaseResp` type to include this new field and modifies the `prettyPrintDatabase` function to display the database edition in the output table. The possible values for the edition are `STANDARD` and `ENTERPRISE`. If the edition is not specified or is `DATABASE_EDITION_UNSPECIFIED`, it will default to `STANDARD`. Also refactors the tests for `prettyPrintDatabase` to improve readability and maintainability and adds a test case for the `STANDARD` edition. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> * Formatted --------- Co-authored-by: Jake Ouellette <jakeout@google.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Google Open Source Bot <firebase-oss-bot@google.com> Co-authored-by: Fred Zhang <fredzqm@google.com> Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Sam Edson <samedson@google.com> Co-authored-by: Ehsan <ehsann@google.com>
Description
Experimenting with making Gemini write tests for some of the less loved areas of our codebase - in this case, the apps-* commands
Scenarios Tested
No behavior changes here, just passing tests.