Skip to content

[_]: feat(email)/add mail username validation decorator and tests#94

Merged
xabg2 merged 2 commits into
masterfrom
fix/mail-address-validation
Jul 17, 2026
Merged

[_]: feat(email)/add mail username validation decorator and tests#94
xabg2 merged 2 commits into
masterfrom
fix/mail-address-validation

Conversation

@jzunigax2

@jzunigax2 jzunigax2 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
  • Implemented the IsMailUsername decorator to validate email usernames based on specified rules, including length, allowed characters, and reserved names.
  • Created unit tests for the isValidMailUsername function to ensure correct validation behavior.
  • Updated CreateMailAccountDto and CheckAvailabilityQueryDto to utilize the new IsMailUsername decorator for username validation.Ñ:

Summary by CodeRabbit

  • New Features

    • Added consistent mail username validation across account creation and username availability checks.
    • Usernames are normalized to lowercase automatically.
    • Validation now enforces length, supported characters, separator rules, and reserved-name restrictions.
    • Improved validation messages explain acceptable username formats.
  • Tests

    • Added coverage for valid usernames, invalid formats, reserved names, unsupported inputs, and DTO validation behavior.

- Implemented the `IsMailUsername` decorator to validate email usernames based on specified rules, including length, allowed characters, and reserved names.
- Created unit tests for the `isValidMailUsername` function to ensure correct validation behavior.
- Updated `CreateMailAccountDto` and `CheckAvailabilityQueryDto` to
  utilize the new `IsMailUsername` decorator for username validation.Ñ:
@jzunigax2
jzunigax2 requested a review from xabg2 July 16, 2026 19:17
@jzunigax2 jzunigax2 self-assigned this Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jzunigax2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 29 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33b8c69a-2cd9-45bd-b291-faf9c357cc9e

📥 Commits

Reviewing files that changed from the base of the PR and between c46fdc2 and be5db4c.

📒 Files selected for processing (2)
  • src/modules/account/dto/create-mail-account.dto.ts
  • src/modules/addresses/addresses.dto.ts
📝 Walkthrough

Walkthrough

A reusable mail-username validator and decorator are added, with normalization and validation applied to account creation and availability query DTOs. Vitest coverage verifies valid, invalid, reserved, and non-string inputs.

Changes

Mail username validation

Layer / File(s) Summary
Validator contract and implementation
src/common/decorators/is-mail-username.decorator.ts
Defines username length bounds, reserved names, character rules, the isValidMailUsername helper, and the IsMailUsername class-validator decorator.
DTO normalization and integration
src/modules/account/dto/create-mail-account.dto.ts, src/modules/addresses/addresses.dto.ts
Lowercases account addresses and availability-query usernames before applying IsMailUsername.
Validator behavior coverage
src/common/decorators/is-mail-username.decorator.spec.ts
Tests valid and invalid helper inputs and verifies decorator validation errors and constraints.

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

Sequence Diagram(s)

sequenceDiagram
  participant Request
  participant DTO
  participant IsMailUsername
  participant isValidMailUsername
  Request->>DTO: provide username or address
  DTO->>DTO: lowercase input
  DTO->>IsMailUsername: validate normalized value
  IsMailUsername->>isValidMailUsername: check username rules
  isValidMailUsername-->>IsMailUsername: return validation result
  IsMailUsername-->>DTO: report validation result
Loading

Suggested labels: enhancement

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding mail username validation logic and tests.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mail-address-validation

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/common/decorators/is-mail-username.decorator.ts (1)

58-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use $property token for dynamic validation messages.

The validation message hardcodes the field name as "address". Since this decorator is used on both address and username properties across different DTOs, the error message will be slightly misleading when it fails for username.

Use the $property token built into class-validator to dynamically inject the correct property name.

♻️ Proposed refactor
   defaultMessage(): string {
-    return `address must be ${MAIL_USERNAME_MIN_LENGTH}-${MAIL_USERNAME_MAX_LENGTH} characters, contain only lowercase letters, numbers, ".", "-" or "_", not start/end with a special character or repeat one, and not be a reserved name`;
+    return `$property must be ${MAIL_USERNAME_MIN_LENGTH}-${MAIL_USERNAME_MAX_LENGTH} characters, contain only lowercase letters, numbers, ".", "-" or "_", not start/end with a special character or repeat one, and not be a reserved name`;
   }
🤖 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/common/decorators/is-mail-username.decorator.ts` around lines 58 - 60,
Update the defaultMessage method in the mail username validation decorator to
use class-validator’s $property token instead of hardcoding “address,” so
failures identify the actual decorated property such as address or username
while preserving the rest of the message.
🤖 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/modules/account/dto/create-mail-account.dto.ts`:
- Around line 35-36: Update the `@Transform` decorator on the username property in
src/modules/account/dto/create-mail-account.dto.ts:35-36 and the corresponding
transform in src/modules/addresses/addresses.dto.ts:13-14 to call toLowerCase
only when value is a string, otherwise return it unchanged. Apply the same
safeguard to the domain property in src/modules/addresses/addresses.dto.ts if it
uses the same unsafe transformation, preserving class-validator’s handling of
invalid non-string inputs.

---

Nitpick comments:
In `@src/common/decorators/is-mail-username.decorator.ts`:
- Around line 58-60: Update the defaultMessage method in the mail username
validation decorator to use class-validator’s $property token instead of
hardcoding “address,” so failures identify the actual decorated property such as
address or username while preserving the rest of the message.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd8ae7b5-3915-44d7-b7ae-7b102be307a2

📥 Commits

Reviewing files that changed from the base of the PR and between c991d4b and c46fdc2.

📒 Files selected for processing (4)
  • src/common/decorators/is-mail-username.decorator.spec.ts
  • src/common/decorators/is-mail-username.decorator.ts
  • src/modules/account/dto/create-mail-account.dto.ts
  • src/modules/addresses/addresses.dto.ts

Comment thread src/modules/account/dto/create-mail-account.dto.ts Outdated
- Updated the transformation logic in `CreateMailAccountDto` and `CheckAvailabilityQueryDto` to ensure that only string values are converted to lowercase, improving type safety and preventing potential runtime errors.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
69.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@xabg2
xabg2 merged commit a51f1d8 into master Jul 17, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants