Skip to content

test: improve coverage for init auth#10394

Open
joehan wants to merge 1 commit intonextfrom
test/init-auth
Open

test: improve coverage for init auth#10394
joehan wants to merge 1 commit intonextfrom
test/init-auth

Conversation

@joehan
Copy link
Copy Markdown
Member

@joehan joehan commented Apr 21, 2026

Description\nImplement unit tests for init auth feature.\n\n### Scenarios Tested\n- Email provider selection\n- Google provider selection and prompts\n- Actuate generating config

### Description\nImplement unit tests for init auth feature.\n\n### Scenarios Tested\n- Email provider selection\n- Google provider selection and prompts\n- Actuate generating config
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 new test suite for the auth initialization feature, covering provider selection logic and configuration actuation. The review feedback focuses on improving code quality and test stability: specifically, it recommends avoiding unknown type casts to comply with the style guide, using explicit null handling for optional properties, increasing test coverage for the anonymous provider, and providing a dummy project directory when initializing the Config object to prevent environment-dependent side effects.

describe("askQuestions", () => {
it("should handle email provider selection", async () => {
checkboxStub.resolves(["email"]);
const setup = { config: {} } as unknown as Setup;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The repository style guide (Line 38) prohibits using any or unknown as an escape hatch. Instead of double-casting to unknown, consider providing the minimum required properties for the Setup interface (such as rcfile and instructions) or using a more specific type if appropriate. This pattern is repeated in several places in this file (lines 40, 59, and 69).

References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

Comment on lines +32 to +33
expect(setup.featureInfo.auth.providers.emailPassword).to.be.true;
expect(setup.featureInfo.auth.providers.anonymous).to.be.undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The repository style guide (Line 39) requires handling undefined/null explicitly. Since featureInfo is an optional property on the Setup interface, it should be accessed using a non-null assertion or optional chaining to satisfy strict null checks. This also applies to the assertions on lines 44-49 and 64.

Suggested change
expect(setup.featureInfo.auth.providers.emailPassword).to.be.true;
expect(setup.featureInfo.auth.providers.anonymous).to.be.undefined;
expect(setup.featureInfo!.auth.providers.emailPassword).to.be.true;
expect(setup.featureInfo!.auth.providers.anonymous).to.be.undefined;
References
  1. Use strict null checks and handle undefined/null explicitly. (link)

expect(setup.featureInfo.auth.providers.googleSignIn.supportEmail).to.equal(
"support@app.com",
);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The askQuestions function handles the 'Anonymous' provider, but there is no test case covering its selection. Consider adding a test case to ensure full coverage of the provider selection logic.

auth: { providers: { emailPassword: true } },
},
} as unknown as Setup;
const config = new Config({}, {});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Initializing Config without a projectDir in the options will trigger detectProjectRoot, which may have side effects or fail depending on the environment where tests are executed. It is recommended to provide a dummy projectDir to ensure test stability. This also applies to line 70.

Suggested change
const config = new Config({}, {});
const config = new Config({}, { projectDir: "." });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants