test: cover Email Inbox message processing by ricardogarim · Pull Request #42999 · RocketChat/Rocket.Chat · GitHub
Skip to content

test: cover Email Inbox message processing - #42999

Queued
ricardogarim wants to merge 2 commits into
developfrom
test/core-2807-email-inbox-processing
Queued

ricardogarim wants to merge 2 commits into
developfrom
test/core-2807-email-inbox-processing

Conversation

@ricardogarim

@ricardogarim ricardogarim commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

The Email Inbox feature reads email through IMAP and sends replies through SMTP. When an email arrives, the visitor's email shows as a livechat message in the room of its email thread, with its files. When an agent quotes that message, the visitor gets the reply by email in the same thread. Agents can also send message files by email, and admins can send a test email to check an inbox.

This PR adds node:test unit tests next to the three Email Inbox files. The tests cover the inbox setup, the incoming email flow, and the outgoing replies, files and test email. The model fakes use registerModel in before().

The first commit moves the registerModel calls of cleanRoomHistory.test.ts into before(). All unit test files run in one process, and that file registered its fakes when it loaded. The new tests replaced its IMessagesModel fake, and 4 of its tests failed.

Coverage and mutation
File Lines before Lines after
EmailInbox.ts 0% 94.3%
EmailInbox_Incoming.ts 0% 96.3%
EmailInbox_Outgoing.ts 0% 92.9%

Before this PR, no unit test loaded these files, and Codecov does not list them. The "after" values come from nyc.

Mutation (by hand, 68 mutants): 67 killed. The mutant that stays changes !match?.groups to !match. It does not change the result, because every match of the regex includes its named groups.

Issue(s)

Steps to test or reproduce

In apps/meteor, run yarn .testunit:server.

Further comments

  • EmailInbox.ts calls void onEmailReceived(...) in a try/catch, so the catch does not get its errors. When the processing fails (for example, after an admin deletes the department of the inbox), only the global handler logs the error. The history record and the IMAP "seen" flag are already set, so the email is lost. This PR does not change this behavior.
  • In EmailInbox_Outgoing.ts, the afterSaveMessage callback has a second if (!inbox) check that never runs.
  • An end-to-end test of the email flow needs an IMAP and SMTP server in CI. CI has no such server, so this PR covers the flow with unit tests only.

View guided diff

Summary by CodeRabbit

  • Tests
    • Expanded coverage for email inbox setup, incoming email processing, outgoing replies, attachments, threading, validation, and delivery failures.
    • Added scenarios for secure and non-secure mail configurations, inactive inbox handling, duplicate messages, and upload failures.
    • Improved test isolation and mock setup for room history cleanup behavior.

@dionisio-bot

dionisio-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9c25180d-9331-409d-af75-207b711d65bd
📥 Commits

Reviewing files that changed from the base of the PR and between a818995 and a7ec206.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bb06cfd4-7ee7-4311-9053-c52f9c6cbecd
📥 Commits

Reviewing files that changed from the base of the PR and between 2991162 and a818995.

📒 Files selected for processing: 4
  • apps/meteor/server/features/EmailInbox/EmailInbox.test.ts
  • apps/meteor/server/features/EmailInbox/EmailInbox_Incoming.test.ts
  • apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.test.ts
  • apps/meteor/server/lib/rooms/cleanRoomHistory.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout: 3
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
🧰 Additional context used
🪛 Betterleaks (1.9.0)
apps/meteor/server/features/EmailInbox/EmailInbox.test.ts

[high] 62-62: Detected a potential hardcoded password literal, which may expose account credentials.

(generic-password)

[high] 63-63: Detected a potential hardcoded password literal, which may expose account credentials.

(generic-password)

🔇 Additional comments: 4
apps/meteor/server/features/EmailInbox/EmailInbox.test.ts: 1

1-149: LGTM!

apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.test.ts: 1

1-353: LGTM!

apps/meteor/server/features/EmailInbox/EmailInbox_Incoming.test.ts: 1

1-253: LGTM!

apps/meteor/server/lib/rooms/cleanRoomHistory.test.ts: 1

1-1: LGTM!

Also applies to: 52-58

Walkthrough

Added tests for email inbox configuration, incoming and outgoing email handling, and attachment behavior. Updated the room-history test to register mocked models in a suite-level hook.

Changes

Email inbox tests

Layer / File(s) Summary
Inbox configuration and history processing
apps/meteor/server/features/EmailInbox/EmailInbox.test.ts
Tests cover inbox reconfiguration, startup failures, and whether messages are recorded and processed based on message IDs and duplicate-history errors.
Incoming email processing
apps/meteor/server/features/EmailInbox/EmailInbox_Incoming.test.ts
Tests cover visitor resolution, department handling, room selection, message formatting, registration errors, and attachment persistence and notifications.
Outgoing email and attachment delivery
apps/meteor/server/features/EmailInbox/EmailInbox_Outgoing.test.ts
Tests cover reply-by-email, attachment commands, and test email delivery, including failure cases.

Room history test setup

Layer / File(s) Summary
Suite-level mock registration
apps/meteor/server/lib/rooms/cleanRoomHistory.test.ts
Mocked models are now registered in a suite-level before hook instead of at module load time.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Suggested labels: type: chore

Merge Risk: ⚪ Minimal · up to a8189

This PR adds test coverage for Email Inbox processing and has no production behavior change. No merge-blocking risk is evident.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding test coverage for Email Inbox message processing.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4…
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.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4 files.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Errors were encountered while retrieving linked issues.

Errors: 1
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

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.

@changeset-bot

changeset-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a7ec206

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ricardogarim ricardogarim added this to the 8.10.0 milestone Oct 21, 2026
@ricardogarim

Copy link
Copy Markdown
Member Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review

@ricardogarim I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

View guided diff | Re-trigger cubic

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.00%. Comparing base (d747322) to head (a7ec206).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #42999      +/-   ##
===========================================
+ Coverage    70.95%   71.00%   +0.05%     
===========================================
  Files         5193     5193              
  Lines       222993   223034      +41     
  Branches     41294    41240      -54     
===========================================
+ Hits        158221   158366     +145     
+ Misses       59578    59456     -122     
- Partials      5194     5212      +18     
Flag Coverage Δ
e2e 59.31% <ø> (-0.08%) ⬇️
e2e-api 48.82% <ø> (+<0.01%) ⬆️
unit 70.95% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Base automatically changed from test/node-test-runner to develop October 21, 2026 15:24
@ricardogarim
ricardogarim force-pushed the test/core-2807-email-inbox-processing branch from a818995 to a7ec206 Compare October 21, 2026 15:36
@ricardogarim
ricardogarim marked this pull request as ready for review October 21, 2026 16:50
@ricardogarim
ricardogarim requested review from a team as code owners October 21, 2026 16:51

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

View guided diff | Re-trigger cubic

@KevLehman KevLehman modified the milestones: 8.10.0, 9.0.0 Oct 21, 2026
@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Oct 21, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Oct 21, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Oct 21, 2026
Any commits made after this event will not be merged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: chore

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants