Fix/issue-2870 [Team Page] API returns 200 OK and saves leading spaces in name instead of trimming/validation error - #3484
Fix/issue-2870 [Team Page] API returns 200 OK and saves leading spaces in name instead of trimming/validation error#3484Valience wants to merge 7 commits into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. WalkthroughThe change adds a reusable validation message and rejects leading or trailing spaces in team category names and descriptions. Unit tests cover leading, trailing, combined, and valid spacing cases. ChangesTeam category whitespace validation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: 🟡 Moderate · up to The new whitespace validation may crash when Name or Description is null, returning a 500 response instead of a 400 validation error. Merge should wait for null-safe predicates or explicit cascade behavior. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🛠️ Fix failing CI checks
🧪 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.
-
The identical Must(...) + WithMessage(...) pair is copy-pasted for both properties. Given points A1/A2, this rule will be needed on several more DTOs; the repo already has a precedent for factoring such rules out (EventNewsCategoryNameValidationExtensions.cs). Worth extracting before it is copied a third time.
-
Min/max are evaluated on the raw string before the space rule. A 20-char name plus one trailing space (MaxNameLength = 20, TeamCategoryConstants.cs) fails with "maximum length of 20 characters" rather than the space message, because cascade stops at MaximumLength. Not incorrect - the request is rejected either way - but the error tells the admin the wrong thing to fix. Not covered by any test.
-
Tests geps
- No API-level test. The issue is literally "API returns 200 OK", yet there is no test in ControllerTests/TeamCategories/ asserting 400 for a padded name.
- No case for non-space whitespace (\t, \n, \u00A0). string.Trim() strips all of these, so the rule rejects them - that behaviour is untested and could silently change.
- No case for the interaction in padded value whose trimmed length is below MinNameLength, e.g. " abc "
- the two ShouldNotHaveError tests build the exact same valid DTO as the pre-existing Validate_ValidDto_ShouldNotHaveErrors at line 141; they add no coverage.
| nameof(CreateTeamCategoryDto.Name), | ||
| TeamCategoryConstants.MaxNameLength)); | ||
| TeamCategoryConstants.MaxNameLength)) | ||
| .Must(name => name == name.Trim()) |
There was a problem hiding this comment.
Must predicate is null-unsafe; safety comes only from a global static setting
BaseTeamCategoryValidator.cs Line 23 and 39
Name/Description are string ... = null! (CreateTeamCategoryDto.cs), so a request omitting the field yields null. FluentValidation's length validators skip nulls, but Must does not - the predicate dereferences name and throws NullReferenceException.
Today this does not blow up, because rule-level cascade is globally forced to Stop in two places (ServicesConfiguration.cs lines 110, 128) and, for tests, by a [ModuleInitializer] (ValidatorsConfig.cs line 11), so NotEmpty() short-circuits the chain. That is an implicit, action-at-a-distance guarantee: ~30 other validators in this repo defend explicitly with .Cascade(CascadeMode.Stop) (e.g. BaseCompanyProfileContactDtoValidator.cs:12), this one does not. Any consumer that resolves the validator without that global (new test assembly, library reuse, someone flipping the default) turns a 400 into a 500.
Make the rule chain state its own cascade, or write the predicate so it tolerates null.
|
|
||
| public static string PropertyMustNotHaveLeadingOrTrailingSpaces(string property) | ||
| { | ||
| return $"{property} must not have leading or trailing spaces."; |
There was a problem hiding this comment.
Message text ends with a period; no other message in that file does (compare lines 126, 131, 136). These strings surface in the admin UI, so the punctuation is user-visible.
|
The build is failing due to missing constructor parameters in the PDF report handler test files. The handlers now require a Root CauseLooking at the compilation errors: This error appears in:
The handler constructors have been updated to include a SolutionUpdate the handler instantiation in all PDF report test files to include the missing For
|
hae-ctr-mykhailo-klapchuk
left a comment
There was a problem hiding this comment.
Check Halyna's comments
|
✅ Committed CI fixes to this branch (
1 PR-caused check(s)
⏭️ 1 check(s) skipped — already failing on `release/1.0.0` (not caused by this PR)
4 file(s) modified
View agent analysis |
Co-Authored-By: CodeRabbit <noreply@coderabbit.ai>
|




Issue ticket link
Description
Fixes API accepting leading/trailing whitespace in TeamCategory
nameanddescriptionfields.Previously,
PUT /api/TeamCategories/{id}returned 200 OK and persisted values with surroundingwhitespace. Now returns 400 Bad Request with a validation error.
How it looks
Summary of change
ErrorMessagesConstants.cs: AddedPropertyMustNotHaveLeadingOrTrailingSpaces(string property).BaseTeamCategoryValidator.cs: Added.Must(...)rule toNameandDescriptionrejectingvalues that differ from their trimmed form.
BaseTeamCategoryValidatorTests.cs: Added 4 tests covering leading-space, trailing-space,both, and the no-space passing case for both fields.
How to recreate changes
PUT /api/TeamCategories/{id}withnameordescriptioncontaining a leading/trailingspace.
Check List
Summary by CodeRabbit
Bug Fixes
Tests