test(api/auth): fix brittle mock string in resetPassword test (closes #513)#854
test(api/auth): fix brittle mock string in resetPassword test (closes #513)#854cristim wants to merge 2 commits into
Conversation
|
@coderabbitai review |
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 58 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 Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated reset-password tests to mock the exact ChangesPassword Reset Error Test Alignment
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
…513) The mock returned "invalid or expired token" but the real service emits "invalid or expired reset token" (with "reset"). Because isResetPasswordClientError matches the real string, the mismatched mock caused the error to fall through as a 500, but the test never checked the status code, so it passed vacuously. Fix: align the mock to the real service string and assert the error is classified as a 400 client error via IsClientError, which is the invariant the test was meant to guard.
Add t.Cleanup(func(){ mockAuth.AssertExpectations(t) }) to
TestHandler_resetPassword_Error and TestHandler_resetPassword_ErrorIsClientError
so that a future On() call without a corresponding invocation is caught
rather than silently passing.
Summary
TestHandler_resetPassword_Errormock returned"invalid or expired token"but the real service (service_password.go) emits"invalid or expired reset token"(with the extra word "reset").isResetPasswordClientErrormatches the real string (not the mock's), the mismatched mock caused the error to escape as a 500 internally; but no status assertion existed, so the test passed vacuously.IsClientErrorreturns a 400, which is the invariant the test was meant to guard.Test plan
go test github.com/LeanerCloud/CUDly/internal/api/... -run TestHandler_resetPassword_Errorpasses (1852 tests clean)go build ./...cleanisResetPasswordClientErrorcoverageSummary by CodeRabbit