[_]: feat(email)/add mail username validation decorator and tests#94
Conversation
- 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.Ñ:
|
Warning Review limit reached
Next review available in: 29 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA 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. ChangesMail username validation
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
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/common/decorators/is-mail-username.decorator.ts (1)
58-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
$propertytoken for dynamic validation messages.The validation message hardcodes the field name as "address". Since this decorator is used on both
addressandusernameproperties across different DTOs, the error message will be slightly misleading when it fails forusername.Use the
$propertytoken built intoclass-validatorto 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
📒 Files selected for processing (4)
src/common/decorators/is-mail-username.decorator.spec.tssrc/common/decorators/is-mail-username.decorator.tssrc/modules/account/dto/create-mail-account.dto.tssrc/modules/addresses/addresses.dto.ts
- 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.
|


IsMailUsernamedecorator to validate email usernames based on specified rules, including length, allowed characters, and reserved names.isValidMailUsernamefunction to ensure correct validation behavior.CreateMailAccountDtoandCheckAvailabilityQueryDtoto utilize the newIsMailUsernamedecorator for username validation.Ñ:Summary by CodeRabbit
New Features
Tests