Skip to content

[_]: refactor(mail)/simplify mail account key fetching#51

Merged
jzunigax2 merged 4 commits intomasterfrom
fix/make-email-address-optional-param-on-get-keys
May 7, 2026
Merged

[_]: refactor(mail)/simplify mail account key fetching#51
jzunigax2 merged 4 commits intomasterfrom
fix/make-email-address-optional-param-on-get-keys

Conversation

@jzunigax2
Copy link
Copy Markdown
Contributor

Make email address an optional param on get keys method

@jzunigax2 jzunigax2 added the enhancement New feature or request label May 7, 2026
@jzunigax2 jzunigax2 requested a review from xabg2 May 7, 2026 04:20
@jzunigax2 jzunigax2 self-assigned this May 7, 2026
@jzunigax2 jzunigax2 force-pushed the fix/make-email-address-optional-param-on-get-keys branch from 748cde5 to c141b5a Compare May 7, 2026 12:52
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 7, 2026

Deploying mail-web with  Cloudflare Pages  Cloudflare Pages

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

View logs

@jzunigax2 jzunigax2 marked this pull request as ready for review May 7, 2026 15:16
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This 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.

Changes

Optional Address Mail Keys Query

Layer / File(s) Summary
Service & API Contracts
src/services/sdk/mail/index.ts, src/store/api/mail/index.ts
MailService.getMailAccountKeys() and RTK Query getMailAccountKeys endpoint signatures updated to accept optional address?: string and forward arg?.address.
Hook Implementations
src/hooks/mail/useMailKeys.ts, src/hooks/mail/useMailAccountGuard.ts
useMailKeys reads data?.address from useGetMailAccountKeysQuery() and returns cached keys; useMailAccountGuard calls the query unconditionally and returns loading when isLoading or isFetching.
Hook Tests
src/hooks/mail/useMailKeys.test.tsx, src/hooks/mail/useMailAccountGuard.test.tsx
New tests for useMailKeys (unresolved promise, cached keys, cache miss). useMailAccountGuard tests refactored to remove authenticated-user fixture and add cached-keys and missing-mnemonic cases while preserving existing assertions.
Service & API Tests
src/services/sdk/mail/mail.service.test.ts, src/store/api/mail/mail.api.test.ts
Tests added/updated to assert calls without an address dispatch invoke the service with undefined; error-path tests dispatch endpoint without an address.
Dependency Update
package.json
@internxt/sdk bumped from ^1.16.0 to ^1.16.2.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • xabg2
  • larryrider
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: refactoring mail account key fetching by making the email address parameter optional across the codebase.
Description check ✅ Passed The description directly relates to the changeset, clearly stating the primary objective of making email address an optional parameter on the get keys method.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/make-email-address-optional-param-on-get-keys

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

👉 Steps to fix this

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1b5d8d4 and 00a71a6.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (9)
  • package.json
  • src/hooks/mail/useMailAccountGuard.test.tsx
  • src/hooks/mail/useMailAccountGuard.ts
  • src/hooks/mail/useMailKeys.test.tsx
  • src/hooks/mail/useMailKeys.ts
  • src/services/sdk/mail/index.ts
  • src/services/sdk/mail/mail.service.test.ts
  • src/store/api/mail/index.ts
  • src/store/api/mail/mail.api.test.ts

Comment thread src/hooks/mail/useMailAccountGuard.test.tsx Outdated
Comment thread src/hooks/mail/useMailKeys.test.tsx Outdated
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 7, 2026

@jzunigax2
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

✅ 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/hooks/mail/useMailKeys.test.tsx (1)

53-55: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Ensure 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

📥 Commits

Reviewing files that changed from the base of the PR and between 00a71a6 and ffa2a9e.

📒 Files selected for processing (2)
  • src/hooks/mail/useMailAccountGuard.test.tsx
  • src/hooks/mail/useMailKeys.test.tsx

@jzunigax2 jzunigax2 merged commit c2fa38a into master May 7, 2026
6 checks passed
@jzunigax2 jzunigax2 deleted the fix/make-email-address-optional-param-on-get-keys branch May 7, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant