[_]: refactor(mail)/simplify mail account key fetching#51
Conversation
748cde5 to
c141b5a
Compare
Deploying mail-web with
|
| Latest commit: |
ffa2a9e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b59175d6.mail-web-ea0.pages.dev |
| Branch Preview URL: | https://fix-make-email-address-optio.mail-web-ea0.pages.dev |
📝 WalkthroughWalkthroughThis PR makes MailService and the RTK Query endpoint accept an optional address, updates hooks to derive the address from the query response instead of Redux, adjusts guard loading logic, adds/updates tests for no-address and cached-key flows, and bumps an SDK dependency. ChangesOptional Address Mail Keys Query
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 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)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
Warning
CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.
Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.
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 `@src/hooks/mail/useMailAccountGuard.test.tsx`:
- Line 103: The test descriptions currently include the function name
openEncryptionKeystore; update the two test title strings (the one starting at
the test on line with "When decrypted keys are already cached..." and the other
around line 118) to remove any function/identifier names and follow the "When
<situation>, then <expected outcome>" pattern in plain language (e.g., "When
decrypted keys are already cached for the address, then it should not attempt to
load a keystore and should be ready"). Keep the assertions and test body intact,
only change the human-readable test description text to avoid referencing
openEncryptionKeystore or other symbol names.
In `@src/hooks/mail/useMailKeys.test.tsx`:
- Around line 47-56: The test falsely passes because it asserts result.current
=== null before the mocked fetch resolves; update the test to wait for the fetch
to complete and then assert the hook value. Specifically, in the test "When the
address has no cached keys..." remove the rerender() call from inside waitFor,
instead await waitFor(() =>
expect(MailService.instance.getMailAccountKeys).toHaveBeenCalled()) (or await a
resolved promise for the mock), then call rerender() once and assert
result.current is null; reference useMailKeys and
MailService.instance.getMailAccountKeys to locate the code to change.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 25635a5a-7ea5-46f4-bd95-46dc06c955eb
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (9)
package.jsonsrc/hooks/mail/useMailAccountGuard.test.tsxsrc/hooks/mail/useMailAccountGuard.tssrc/hooks/mail/useMailKeys.test.tsxsrc/hooks/mail/useMailKeys.tssrc/services/sdk/mail/index.tssrc/services/sdk/mail/mail.service.test.tssrc/store/api/mail/index.tssrc/store/api/mail/mail.api.test.ts
… hooks with clearer descriptions
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/hooks/mail/useMailKeys.test.tsx (1)
53-55:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winEnsure the “after data loads” assertion actually waits for fetch completion.
At Line 53,
toHaveBeenCalled()only confirms invocation, not resolution. The null assertion at Line 55 can still pass before the async query settles, so this test can be a false positive.Suggested fix
- await waitFor(() => expect(fetchSpy).toHaveBeenCalled()); - rerender(); + await waitFor(() => expect(fetchSpy).toHaveBeenCalledOnce()); + await fetchSpy.mock.results[0]?.value; + rerender(); expect(result.current).toBeNull();🤖 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 `@src/hooks/mail/useMailKeys.test.tsx` around lines 53 - 55, The test currently only waits for fetchSpy to be called but not for the async query to resolve, which can make the later expect(result.current).toBeNull() a false positive; modify the test to await the data settling instead of just invocation—use waitFor to assert the hook result changes (e.g., waitFor(() => expect(result.current).not.toBeNull()) or waitFor(() => expect(fetchSpy).toHaveBeenCalledAndResolved())) before calling rerender and the final expect, targeting the same symbols fetchSpy, waitFor, rerender, and result.current so the assertion runs after the fetch completes.
🤖 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.
Duplicate comments:
In `@src/hooks/mail/useMailKeys.test.tsx`:
- Around line 53-55: The test currently only waits for fetchSpy to be called but
not for the async query to resolve, which can make the later
expect(result.current).toBeNull() a false positive; modify the test to await the
data settling instead of just invocation—use waitFor to assert the hook result
changes (e.g., waitFor(() => expect(result.current).not.toBeNull()) or
waitFor(() => expect(fetchSpy).toHaveBeenCalledAndResolved())) before calling
rerender and the final expect, targeting the same symbols fetchSpy, waitFor,
rerender, and result.current so the assertion runs after the fetch completes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 949fd814-c03d-46f7-875f-f6738c55e733
📒 Files selected for processing (2)
src/hooks/mail/useMailAccountGuard.test.tsxsrc/hooks/mail/useMailKeys.test.tsx



Make email address an optional param on get keys method