test(elysia): split tests by function and add basic coverage - #247
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Warning Review limit reached
Next review available in: 24 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
📝 WalkthroughWalkthroughThe PR reorganizes Elysia test execution into Stateful and stateless Vitest projects, adds Stateful coverage for authentication and provider operations, updates test fixtures, and reformats the generated TanStack route tree without changing routing behavior. ChangesStateful authentication tests
Generated route tree formatting
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (8)
packages/elysia/test/stateful/getProviderTokens.test.ts (1)
6-6: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winBoth titles state 404 while the assertions require 401.
Correct the titles to match the asserted status.
♻️ Proposed fix
- test("returns 404 when no session cookie is present", async () => { + test("returns 401 when no session cookie is present", async () => {- test("returns 404 when session cookie is invalid", async () => { + test("returns 401 when session cookie is invalid", async () => {Also applies to: 11-11
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/elysia/test/stateful/getProviderTokens.test.ts` at line 6, Update the test titles in the relevant test cases, including the one beginning “returns 404 when no session cookie is present,” to state 401 instead of 404, matching their existing assertions.packages/elysia/test/utils.ts (1)
3-10: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winGuard against a missing session cookie instead of using a non-null assertion.
If the response contains no
aura-auth.session_tokencookie,cookieisundefined.parseSetCookie(cookie!)then throws an opaque error inside the parser. A guard produces a clear assertion failure in the calling test.♻️ Proposed fix
export const getSessionToken = (response: Response) => { const cookie = response.headers.getSetCookie()?.find((cookie) => cookie.startsWith("aura-auth.session_token=")) - const parsed = parseSetCookie(cookie!) + if (!cookie) { + return { cookie: undefined, tokenValue: undefined } + } + const parsed = parseSetCookie(cookie) return { cookie, tokenValue: parsed?.value, } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/elysia/test/utils.ts` around lines 3 - 10, Update getSessionToken to explicitly assert that the aura-auth.session_token cookie was found before calling parseSetCookie, replacing the non-null assertion with a clear failure for missing cookies while preserving the existing parsed token return.packages/elysia/test/stateful/signIn.test.ts (2)
74-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReuse
getSessionTokenfrom@test/utils.These four lines re-implement the helper added in
packages/elysia/test/utils.ts. Import the helper and remove the duplicated cookie lookup and parsing.♻️ Proposed fix
+import { getSessionToken } from "`@test/utils`"- const sessionToken = request.headers.getSetCookie()?.find((cookie) => cookie.startsWith("aura-auth.session_token=")) - expect(sessionToken).toBeDefined() + const { cookie: sessionToken, tokenValue } = getSessionToken(request) + expect(sessionToken).toBeDefined()- const parsed = parseSetCookie(sessionToken!) const session = await app.handle( new Request("http://localhost:3000/api/auth/session", { - headers: { Cookie: `aura-auth.session_token=${parsed.value}` }, + headers: { Cookie: `aura-auth.session_token=${tokenValue}` }, }) )Also applies to: 103-103, 238-238, 241-241
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/elysia/test/stateful/signIn.test.ts` at line 74, Update the sign-in tests to import and reuse getSessionToken from `@test/utils`, replacing the duplicated session-token cookie lookup and parsing at each affected location. Remove the local implementations while preserving the existing assertions and test behavior.
96-96: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDo not hardcode the library version in the User-Agent assertion.
Aura Auth/0.8.1breaks on every version bump of the core package. Read the version from the package manifest or match with a regular expression.♻️ Proposed fix
- "User-Agent": `Aura Auth/0.8.1`, + "User-Agent": expect.stringMatching(/^Aura Auth\/\d+\.\d+\.\d+/),Also applies to: 231-231
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/elysia/test/stateful/signIn.test.ts` at line 96, Update the User-Agent assertions in the sign-in tests to derive the Aura Auth version from the package manifest or match the version portion with a regular expression, instead of hardcoding “0.8.1”.packages/elysia/test/stateful/signOut.test.ts (1)
7-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAlign the test title with the asserted status.
The title states "returns 401 or clears session". The assertion requires 403. Name the expected behavior exactly.
♻️ Proposed fix
- test("returns 401 or clears session when no active session cookie is present", async () => { + test("returns 403 when no active session cookie is present", async () => {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/elysia/test/stateful/signOut.test.ts` around lines 7 - 13, Update the test title in the sign-out test to state that it returns 403 when no active session cookie is present, matching the existing response.status assertion and removing the inaccurate 401 or session-clearing wording.packages/elysia/test/stateful/getSession.test.ts (1)
170-170: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRename this duplicate test title.
Line 97 already declares
"returns 401 for revoked session". This test verifies soft revocation withdeleteStrategy: soft. A distinct title makes failures identifiable.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/elysia/test/stateful/getSession.test.ts` at line 170, Rename the test at the duplicate title near the soft-revocation case to clearly identify that it covers revoked sessions with deleteStrategy: soft, while leaving the existing test title near line 97 unchanged.packages/elysia/vitest.config.ts (1)
49-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftSkipping the stateful project in CI removes all new coverage from CI.
The new stateful suites never run in CI. Regressions in OAuth, session, and provider flows will not be detected by the pipeline. If the suites need a database, gate them on a service container or a dedicated CI job instead of disabling them.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/elysia/vitest.config.ts` around lines 49 - 60, Update the Vitest project configuration around statefulProject so the stateful test suites run in CI instead of being skipped. Keep their database-dependent requirements explicit by wiring them to an available service container or dedicated CI job, while preserving the existing stateless project configuration and coverage for OAuth, session, and provider flows.packages/elysia/test/stateful/isProviderConnected.test.ts (1)
15-15: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTwo tests share the title "returns false when provider is not connected".
The test at line 15 covers a user with no account. The test at line 50 covers a user with a credentials-only account. Distinct titles make failures identifiable.
♻️ Proposed fix
- test("returns false when provider is not connected", async () => { + test("returns false when the user has only a credentials account", async () => { const user = await adapter.createUser({ name: "John Doe", email: "john.doe@example.com", })Also applies to: 50-50
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/elysia/test/stateful/isProviderConnected.test.ts` at line 15, Rename the duplicate test titles in isProviderConnected.test.ts so the no-account case and credentials-only-account case have distinct, descriptive names; preserve each test’s existing behavior and assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/elysia/test/stateful/disconnectProvider.test.ts`:
- Around line 38-69: Update the session setup in the “fails when provider is not
connected” test to store the hash of the session token via the existing
createHash helper, while keeping the raw token value in the request cookie.
Ensure session lookup succeeds so the test reaches and verifies the
provider-not-connected response path.
In `@packages/elysia/test/stateful/getSession.test.ts`:
- Around line 70-88: Fix the session fixtures to follow the endpoint token
contract: in packages/elysia/test/stateful/getSession.test.ts lines 70-88 and
102-120, and packages/elysia/test/stateful/signOut.test.ts lines 72-101, store
the single hash of each raw cookie token as tokenHash; in
packages/elysia/test/stateful/getProviderTokens.test.ts lines 22-55, hash the
raw token once for storage and send the unhashed token in the cookie so each
test exercises its intended session path.
- Line 198: Update the session status assertion in the test to use Vitest’s
toHaveProperty matcher with status set to "REVOKED" instead of haveOwnProperty.
Handle a possible null result from prismaClient.session.findUnique before
applying the property assertion.
In `@packages/elysia/test/stateful/updateSession.test.ts`:
- Line 6: Rename the affected test titles in updateSession.test.ts, including
the tests around the no-session-cookie and related cases, from “returns 404” to
“returns 400” so each title matches its asserted status code.
In `@packages/elysia/vitest.config.ts`:
- Around line 13-29: Update the statefulProject selection in vitest.config.ts so
the CI === "true" branch omits the project configuration rather than returning
an empty object, and adjust the projects array construction to exclude that
entry in CI while retaining the configured stateful project locally.
---
Nitpick comments:
In `@packages/elysia/test/stateful/getProviderTokens.test.ts`:
- Line 6: Update the test titles in the relevant test cases, including the one
beginning “returns 404 when no session cookie is present,” to state 401 instead
of 404, matching their existing assertions.
In `@packages/elysia/test/stateful/getSession.test.ts`:
- Line 170: Rename the test at the duplicate title near the soft-revocation case
to clearly identify that it covers revoked sessions with deleteStrategy: soft,
while leaving the existing test title near line 97 unchanged.
In `@packages/elysia/test/stateful/isProviderConnected.test.ts`:
- Line 15: Rename the duplicate test titles in isProviderConnected.test.ts so
the no-account case and credentials-only-account case have distinct, descriptive
names; preserve each test’s existing behavior and assertions.
In `@packages/elysia/test/stateful/signIn.test.ts`:
- Line 74: Update the sign-in tests to import and reuse getSessionToken from
`@test/utils`, replacing the duplicated session-token cookie lookup and parsing at
each affected location. Remove the local implementations while preserving the
existing assertions and test behavior.
- Line 96: Update the User-Agent assertions in the sign-in tests to derive the
Aura Auth version from the package manifest or match the version portion with a
regular expression, instead of hardcoding “0.8.1”.
In `@packages/elysia/test/stateful/signOut.test.ts`:
- Around line 7-13: Update the test title in the sign-out test to state that it
returns 403 when no active session cookie is present, matching the existing
response.status assertion and removing the inaccurate 401 or session-clearing
wording.
In `@packages/elysia/test/utils.ts`:
- Around line 3-10: Update getSessionToken to explicitly assert that the
aura-auth.session_token cookie was found before calling parseSetCookie,
replacing the non-null assertion with a clear failure for missing cookies while
preserving the existing parsed token return.
In `@packages/elysia/vitest.config.ts`:
- Around line 49-60: Update the Vitest project configuration around
statefulProject so the stateful test suites run in CI instead of being skipped.
Keep their database-dependent requirements explicit by wiring them to an
available service container or dedicated CI job, while preserving the existing
stateless project configuration and coverage for OAuth, session, and provider
flows.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f87ccd97-8e01-4f05-8864-25011aa64b8d
📒 Files selected for processing (18)
apps/tanstack-start/src/routeTree.gen.tspackages/elysia/package.jsonpackages/elysia/test/stateful/app.tspackages/elysia/test/stateful/disconnectProvider.test.tspackages/elysia/test/stateful/getProviderTokens.test.tspackages/elysia/test/stateful/getSession.test.tspackages/elysia/test/stateful/index.test.tspackages/elysia/test/stateful/isProviderConnected.test.tspackages/elysia/test/stateful/refreshUserInfo.test.tspackages/elysia/test/stateful/revokeToken.test.tspackages/elysia/test/stateful/setup.tspackages/elysia/test/stateful/signIn.test.tspackages/elysia/test/stateful/signInCredentials.test.tspackages/elysia/test/stateful/signOut.test.tspackages/elysia/test/stateful/signUp.test.tspackages/elysia/test/stateful/updateSession.test.tspackages/elysia/test/utils.tspackages/elysia/vitest.config.ts
💤 Files with no reviewable changes (1)
- packages/elysia/test/stateful/index.test.ts
Description
This pull request reorganizes the test suite by splitting tests into dedicated files for each function and adding basic test coverage for the individual modules exposed by the
@aura-stack/authcore package.Previously, most Stateful session tests were contained in a single file that continued to grow as new features and test cases were added. This made the test suite increasingly difficult to navigate, understand, and maintain. To improve the testing structure, the tests have been reorganized into smaller, function-specific files.
In addition to the reorganization, this PR introduces basic coverage for the newly separated modules to ensure each function has an initial set of tests.
Key Changes
Note
During this refactor, it became apparent that some modules do not yet have comprehensive edge case or complex scenario coverage. Addressing those cases is intentionally out of scope for this PR. The primary goal is to improve the organization of the test suite and establish a solid baseline of coverage. Additional test cases will be added in future pull requests.
@coderabbitai ignore