Skip to content

test(api/auth): fix brittle mock string in resetPassword test (closes #513)#854

Open
cristim wants to merge 2 commits into
mainfrom
fix/513-wave16
Open

test(api/auth): fix brittle mock string in resetPassword test (closes #513)#854
cristim wants to merge 2 commits into
mainfrom
fix/513-wave16

Conversation

@cristim

@cristim cristim commented May 30, 2026

Copy link
Copy Markdown
Member

Summary

  • The TestHandler_resetPassword_Error mock returned "invalid or expired token" but the real service (service_password.go) emits "invalid or expired reset token" (with the extra word "reset").
  • Because isResetPasswordClientError matches 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.
  • Fix: align the mock to the real service string and assert IsClientError returns 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_Error passes (1852 tests clean)
  • go build ./... clean
  • No new string literals introduced; mock now matches isResetPasswordClientError coverage

Summary by CodeRabbit

  • Tests
    • Strengthened password reset failure coverage to ensure the “invalid or expired reset token” message is preserved and translated into a 400 client error.
    • Added stricter mock verification to confirm the password reset confirmation step is called as expected, improving test reliability.

@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline impact/internal Team-internal only effort/xs Trivial / one-liner type/chore Maintenance / non-user-visible labels May 30, 2026
@cristim

cristim commented May 30, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d6da9daa-f395-4c5b-970b-3c0ebfa2498b

📥 Commits

Reviewing files that changed from the base of the PR and between 762b3c2 and 087373f.

📒 Files selected for processing (1)
  • internal/api/handler_auth_test.go
📝 Walkthrough

Walkthrough

Updated reset-password tests to mock the exact ConfirmPasswordReset error and assert a 400 client error while preserving its message.

Changes

Password Reset Error Test Alignment

Layer / File(s) Summary
Reset password error test alignment
internal/api/handler_auth_test.go
Updated the mocked error text, verified 400 client-error classification and message preservation, and added mock expectation assertions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • LeanerCloud/CUDly#489: Related reset-password tests verify 400 client-error wrapping and preserved token error messages.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the change: it fixes the resetPassword test mock string and asserts the client-error behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/513-wave16

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented Jun 6, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
cristim changed the base branch from feat/multicloud-web-frontend to main June 9, 2026 15:43
@cristim

cristim commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

cristim added 2 commits July 17, 2026 21:26
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant