test(core): add client mocks to cover all core functions#170
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
📝 WalkthroughWalkthroughThe PR simplifies the credentials API 401 JSON to ChangesAuth Credentials Response and Client Adaptation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 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: 2
🤖 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/core/test/client/client.test.ts`:
- Around line 224-230: Update the test "signInCredentials with invalid
credentials" so the mocked HTTP response mirrors the real API status for invalid
credentials: change the POST mock (the vi.fn() assigned to post) to return a
response with HTTP status 401 instead of 200 by passing the 401 status to
createJSONResponse (or setting status: 401 on the mocked response object) — this
ensures the post mock and createJSONResponse usage in the test matches the API
contract for the invalid-credentials flow.
- Around line 284-287: The test constructs an expires Date using
Math.floor(Date.now() / 1000) (seconds) but passes it into new Date(...) which
expects milliseconds, causing an incorrect timestamp; update the expires
construction in the client.test.ts cases (the variable named expires used in the
call to client.updateSession and the later round-trip check of session.expires)
to use milliseconds instead — e.g., use Date.now() + 60 * 60 * 1000 or remove
the /1000 and Math.floor so new Date(...) receives milliseconds — so the
session.expires round-trip via new Date(session.expires) is correct.
🪄 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
Run ID: bed72fcc-2817-409c-8da2-b2d92e232be2
📒 Files selected for processing (3)
packages/core/src/api/credentials.tspackages/core/src/client/client.tspackages/core/test/client/client.test.ts
Description
This pull request adds client-side mocks to provide complete test coverage for all core client functions exposed by
createAuthClient.The new tests expand authentication flow coverage across:
The test suite now validates behavior for:
signInsignInCredentialssignOutsessionupdateSessionThese additions improve reliability and ensure consistent behavior across the client authentication APIs.