Skip to content

test: cover when the mention-not-in-room warning is skipped - #44183

Open
Jisukumarmishra wants to merge 1 commit into
RocketChat:developfrom
Jisukumarmishra:test/mention-not-in-channel-time-rule
Open

Jisukumarmishra wants to merge 1 commit into
RocketChat:developfrom
Jisukumarmishra:test/mention-not-in-channel-time-rule

Conversation

@Jisukumarmishra

@Jisukumarmishra Jisukumarmishra commented Dec 4, 2026 •

Copy link
Copy Markdown

Proposed changes : ---- >

Resolves // TODO: check if I need to test this 60 second rule. in apps/meteor/server/hooks/messages/mentionUserNotInChannel.ts.

The mention-user-not-in-channel afterSaveMessage hook warns the author when a message mentions people who aren't in the room. It skips edited messages and messages older than 60 seconds (e.g. imported), since notifications are skipped for those too. The hook had no unit test.

New mentionUserNotInChannel.test.ts loads the hook with its dependencies stubbed and covers:

a new message mentioning someone not in the room triggers the warning;
a message sent 30 seconds ago still does;
a message older than 60 seconds is skipped without querying subscriptions;
an edited message is skipped the same way.
The only source change is removing the TODO line.

Decisions and gaps
Test-only change; no changeset.
The tests check behaviour, not how the age is computed, so they keep passing after #40077 moves this line from moment to date-fns. #43710 changes what the warning says, not when it is sent, so it doesn't affect them either.
Checked that the tests catch regressions: removing the 60-second condition, or the edited-message condition, from the hook makes them fail.
Issue(s)
None.

Steps to test or reproduce
apps/meteor → yarn .testunit:server (server/hooks/messages/mentionUserNotInChannel.test.ts).

View guided diff

Summary by CodeRabbit

  • Tests
    • Expanded automated coverage for warnings related to mentioning people outside a channel, including checks for message age and edited messages. These checks help ensure warning behavior remains consistent across these scenarios.

The mention-user-not-in-channel hook skips edited messages and messages
older than 60 seconds, as the TODO asked to test. Add unit tests for the
warning being sent for new messages and skipped for old or edited ones.
@Jisukumarmishra
Jisukumarmishra requested a review from a team as a code owner December 4, 2026 19:22
@dionisio-bot

dionisio-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Dec 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b74f31e

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

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/server/hooks/messages/mentionUserNotInChannel.test.ts">

<violation number="1" location="apps/meteor/server/hooks/messages/mentionUserNotInChannel.test.ts:67">
P3: This test only checks that a warning was broadcast to the author in the room. It doesn't check the payload, so a regression that lists the wrong users or drops the mention would still pass. Assert the 4th broadcast argument's `mentions` contains Bob.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

await afterSaveMessage(messageMentioningBob(), { room });

expect(findByRoomIdAndUserIds.calledOnce).to.be.true;
expect(broadcast.calledOnceWith('notify.ephemeralMessage', 'alice', 'room1')).to.be.true;

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.

P3: This test only checks that a warning was broadcast to the author in the room. It doesn't check the payload, so a regression that lists the wrong users or drops the mention would still pass. Assert the 4th broadcast argument's mentions contains Bob.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At apps/meteor/server/hooks/messages/mentionUserNotInChannel.test.ts, line 67:

<comment>This test only checks that a warning was broadcast to the author in the room. It doesn't check the payload, so a regression that lists the wrong users or drops the mention would still pass. Assert the 4th broadcast argument's `mentions` contains Bob.</comment>

<file context>
@@ -0,0 +1,95 @@
+		await afterSaveMessage(messageMentioningBob(), { room });
+
+		expect(findByRoomIdAndUserIds.calledOnce).to.be.true;
+		expect(broadcast.calledOnceWith('notify.ephemeralMessage', 'alice', 'room1')).to.be.true;
+	});
+
</file context>

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds tests for the mentionUserNotInChannel callback. It checks warning broadcasts for recent messages and skipped processing for old or edited messages. The change also removes a TODO comment. Executable behavior is unchanged.

Changes

Mention callback tests

Layer / File(s) Summary
Verify mention callback behavior
apps/meteor/server/hooks/messages/mentionUserNotInChannel.test.ts, apps/meteor/server/hooks/messages/mentionUserNotInChannel.ts
Tests cover callback registration, warning broadcasts for recent messages, and skipped processing for old or edited messages. The TODO comment about the 60-second rule is removed.

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

Change: Other

Suggested labels: type: chore

Suggested reviewers: gabriellsh

Merge Risk: Minimal · up to b74f3

This is a test-only change with a comment removal and no production behavior change. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change accurately: the PR adds unit tests that cover when the mention-not-in-room warning is skipped. The objectives say the tests cover messages older than 60 seconds and edited m…
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: Title check

Explanation

The title names the change accurately: the PR adds unit tests that cover when the mention-not-in-room warning is skipped. The objectives say the tests cover messages older than 60 seconds and edited messages being skipped, which matches the title. The title is short, uses a conventional prefix, and is specific enough for a teammate scanning history. It does not mention the TODO removal, but that is a minor part of the change.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8148cfe8-4e52-41ae-96b1-4bbe83700b4c
Commits

Reviewing files that changed from the base of the PR and between 24f831a and b74f31e.

Files selected for processing: 2

  • apps/meteor/server/hooks/messages/mentionUserNotInChannel.test.ts
  • apps/meteor/server/hooks/messages/mentionUserNotInChannel.ts
Files with no reviewable changes: 1

  • apps/meteor/server/hooks/messages/mentionUserNotInChannel.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: 2

  • GitHub Check: CodeRabbit
  • GitHub Check: Layne Security Scan
Additional context used

Learnings: 2

Learning: 2026-02-26T19:25:44.063Z

Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/hooks/messages/mentionUserNotInChannel.test.ts
Learning: 2026-02-26T19:25:44.063Z

Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/hooks/messages/mentionUserNotInChannel.test.ts

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant