Skip to content

refactor: migrate rooms.nameExists to new route pattern#39309

Open
Rohitgiri02 wants to merge 3 commits intoRocketChat:developfrom
Rohitgiri02:migrate/rooms-nameexists
Open

refactor: migrate rooms.nameExists to new route pattern#39309
Rohitgiri02 wants to merge 3 commits intoRocketChat:developfrom
Rohitgiri02:migrate/rooms-nameexists

Conversation

@Rohitgiri02
Copy link
Contributor

@Rohitgiri02 Rohitgiri02 commented Mar 3, 2026


Proposed Changes

  • Migrated /v1/rooms.nameExists from the legacy API.v1.addRoute() pattern to
    the new chained .get() pattern on roomEndpoints with full AJV request/response
    validation.
  • Removed the manual /v1/rooms.nameExists definition (GETRoomsNameExists,
    GETRoomsNameExistsSchema, isGETRoomsNameExists) from
    @rocket.chat/rest-typings.
  • Updated the existing end-to-end test for rooms.nameExists to align with the
    new route validation behavior.

Why

The Migration

The codebase is migrating away from manually defining REST endpoint types in
@rocket.chat/rest-typings toward automatically extracting them from the API
implementation using ExtractRoutesFromAPI + module augmentation:

// apps/meteor/app/api/server/v1/rooms.ts
type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints>;

declare module '@rocket.chat/rest-typings' {
  interface Endpoints extends RoomEndpoints {}
}

Benefits:

  • Types are co-located with their implementation — no duplication.
  • Adds proper AJV request query schema + 200/400/401 response validation.
  • Stricter return types.
  • OpenAPI spec is automatically generated from the implementation.

The Test Fix

After migrating to the new chained .get() pattern, the HTTP router layer
validates query params before the auth middleware runs. The old
API.v1.addRoute() + validateParams checked auth first, then params.

This means the unauthenticated test case:

it('should return 401 unauthorized when user is not logged in')

previously sent a request with no roomName param, which was fine because auth
was checked first. With the new pattern, the missing roomName param is caught
first by AJV validation, returning 400 Bad Request before auth is even checked.

Fix: Pass a valid roomName query param in the unauthenticated test. The
router then passes validation and reaches the auth check, which correctly returns
401 Unauthorized.


Test Results

Screenshot 2026-03-03 174333

Summary by CodeRabbit

  • New Features

    • Added a GET endpoint to check whether a room name exists; returns { exists: boolean }.
  • Bug Fixes

    • Improved query validation and consistent 200/400/401 responses for the name-check endpoint.
  • Refactor

    • Moved and integrated the name-check route into the consolidated room endpoints (authenticated).
  • Tests

    • Updated end-to-end test to include the roomName query parameter for the name-check endpoint.

@Rohitgiri02 Rohitgiri02 requested review from a team as code owners March 3, 2026 19:30
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Mar 3, 2026

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
Copy link

changeset-bot bot commented Mar 3, 2026

⚠️ No Changeset found

Latest commit: a145b65

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

Walkthrough

Added a GET rooms.nameExists route inside the consolidated roomEndpoints (with query validation and auth), removed the standalone registration and corresponding REST typing definitions, and adjusted tests to include the roomName query in an unauthorized request.

Changes

Cohort / File(s) Summary
Endpoint Implementation
apps/meteor/app/api/server/v1/rooms.ts
Removed legacy standalone route and import; added GET rooms.nameExists into roomEndpoints with authRequired, query validation for roomName, response shape, and handler returning exists boolean; updated RoomEndpoints type intersections to include roomsSaveNotificationEndpoint.
Public typings
packages/rest-typings/src/v1/rooms.ts
Deleted GETRoomsNameExists type, GETRoomsNameExistsSchema, isGETRoomsNameExists validator, and the /v1/rooms.nameExists GET entry from RoomsEndpoints.
End-to-End Tests
apps/meteor/tests/end-to-end/api/rooms.ts
Updated unauthorized test request to include roomName=test query parameter for the rooms.nameExists endpoint.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: chore

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the primary change: refactoring the rooms.nameExists endpoint to use a new route pattern, which is the core objective of the PR.

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

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

@Rohitgiri02 Rohitgiri02 changed the title refractor: migrate rooms.nameExists to new route pattern and fix dependent packages refactor: migrate rooms.nameExists to new route pattern and fix dependent packages Mar 3, 2026
Copy link
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 3 files

@Rohitgiri02 Rohitgiri02 changed the title refactor: migrate rooms.nameExists to new route pattern and fix dependent packages refactor: migrate rooms.nameExists to new route pattern Mar 3, 2026
Copy link
Contributor

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/app/api/server/v1/rooms.ts (1)

1253-1256: ⚠️ Potential issue | 🟡 Minor

Duplicate type extraction.

ExtractRoutesFromAPI<typeof roomEndpoints> appears twice (lines 1253 and 1254). This is redundant and likely a copy-paste oversight.

Proposed fix
-type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> &
-	ExtractRoutesFromAPI<typeof roomEndpoints> &
+type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> &
 	ExtractRoutesFromAPI<typeof roomDeleteEndpoint> &
 	ExtractRoutesFromAPI<typeof roomsSaveNotificationEndpoint>;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/api/server/v1/rooms.ts` around lines 1253 - 1256,
RoomEndpoints currently includes ExtractRoutesFromAPI<typeof roomEndpoints>
twice; remove the duplicate occurrence so RoomEndpoints is composed only once
from roomEndpoints plus the other endpoints (roomDeleteEndpoint,
roomsSaveNotificationEndpoint) using ExtractRoutesFromAPI to avoid redundancy
and keep the same union of types.
🧹 Nitpick comments (1)
apps/meteor/app/api/server/v1/rooms.ts (1)

1013-1045: Clean migration to the new route pattern.

The endpoint correctly implements AJV query/response validation with efficient projection. One optional improvement: consider adding minLength: 1 to the roomName schema (similar to line 297) to reject empty strings at validation time rather than returning exists: false for semantically invalid input.

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/api/server/v1/rooms.ts` around lines 1013 - 1045, The
rooms.nameExists route's query schema allows empty roomName strings; update the
AJV query schema for the 'rooms.nameExists' GET route (the ajv.compile<{
roomName: string }> block) to include "minLength: 1" on the roomName property so
empty strings are rejected at validation time (mirroring the earlier route
pattern) and the handler (action) will only be invoked for non-empty names.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/meteor/app/api/server/v1/rooms.ts`:
- Around line 1253-1256: RoomEndpoints currently includes
ExtractRoutesFromAPI<typeof roomEndpoints> twice; remove the duplicate
occurrence so RoomEndpoints is composed only once from roomEndpoints plus the
other endpoints (roomDeleteEndpoint, roomsSaveNotificationEndpoint) using
ExtractRoutesFromAPI to avoid redundancy and keep the same union of types.

---

Nitpick comments:
In `@apps/meteor/app/api/server/v1/rooms.ts`:
- Around line 1013-1045: The rooms.nameExists route's query schema allows empty
roomName strings; update the AJV query schema for the 'rooms.nameExists' GET
route (the ajv.compile<{ roomName: string }> block) to include "minLength: 1" on
the roomName property so empty strings are rejected at validation time
(mirroring the earlier route pattern) and the handler (action) will only be
invoked for non-empty names.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0f4f59 and a145b65.

📒 Files selected for processing (2)
  • apps/meteor/app/api/server/v1/rooms.ts
  • packages/rest-typings/src/v1/rooms.ts
💤 Files with no reviewable changes (1)
  • packages/rest-typings/src/v1/rooms.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/api/server/v1/rooms.ts
🧠 Learnings (10)
📓 Common learnings
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:54.909Z
Learning: Rocket.Chat monorepo: Jest testMatch pattern '<rootDir>/src/**/*.spec.(ts|js|mjs)' is valid in this repo and used across multiple packages (e.g., packages/tools, ee/packages/omnichannel-services). Do not flag it as invalid in future reviews.
📚 Learning: 2025-11-27T17:56:26.050Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2026-02-24T19:09:01.522Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:01.522Z
Learning: In Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1, avoid introducing logic changes. Only perform scope-tight changes that preserve behavior; style-only cleanups (e.g., removing inline comments) may be deferred to follow-ups to keep the migration PR focused.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: UserBridge.doGetUserRoomIds in packages/apps-engine/src/server/bridges/UserBridge.ts has a bug where it implicitly returns undefined when the app lacks read permission (missing return statement in the else case of the permission check).

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2025-09-16T13:33:49.237Z
Learnt from: cardoso
Repo: RocketChat/Rocket.Chat PR: 36890
File: apps/meteor/tests/e2e/e2e-encryption/e2ee-otr.spec.ts:21-26
Timestamp: 2025-09-16T13:33:49.237Z
Learning: The im.delete API endpoint accepts either a `roomId` parameter (requiring the actual DM room _id) or a `username` parameter (for the DM partner's username). Constructing slug-like identifiers like `user2${Users.userE2EE.data.username}` doesn't work for this endpoint.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2025-09-16T13:33:49.237Z
Learnt from: cardoso
Repo: RocketChat/Rocket.Chat PR: 36890
File: apps/meteor/tests/e2e/e2e-encryption/e2ee-otr.spec.ts:21-26
Timestamp: 2025-09-16T13:33:49.237Z
Learning: In Rocket.Chat test files, the im.delete API endpoint accepts either a `roomId` parameter (requiring the actual DM room _id) or a `username` parameter (for the DM partner's username). It does not accept slug-like constructions such as concatenating usernames together.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2026-02-23T17:53:06.802Z
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:06.802Z
Learning: During PR reviews that touch endpoint files under apps/meteor/app/api/server/v1, enforce strict scope: if a PR targets a specific endpoint (e.g., rooms.favorite), do not propose changes to unrelated endpoints (e.g., rooms.invite) unless maintainers explicitly request them. Focus feedback on the touched endpoint's behavior, API surface, and related tests; avoid broad cross-endpoint changes in the same PR unless requested.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.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/app/api/server/v1/rooms.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 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/app/api/server/v1/rooms.ts

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.

2 participants