fix : added max length guards to session creation validator fields (issue #1402) - #1407
Conversation
📝 WalkthroughWalkthroughThe PR adds maximum-length guards to flashcard and session creation validators. It adds Vitest coverage for valid boundaries, rejected oversized fields, empty values, validation responses, and the default flashcard category. ChangesInput validation limits
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/tests/flashcardValidator.maxLength.unit.test.js (1)
70-78: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest the exact
categoryboundary.This boundary test omits
category. It does not verify that a 100-character category is accepted. Setcategoryto"C".repeat(100)in this request.🤖 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 `@backend/tests/flashcardValidator.maxLength.unit.test.js` around lines 70 - 78, Update the request in the exact-boundary test for validateCreateFlashcard to include category set to a 100-character value using the existing repeat pattern. Keep the question and answer boundary values and assertions unchanged.backend/tests/sessionValidator.maxLength.unit.test.js (1)
91-100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the
topicsToFocusitem limit.The suite does not exercise the new
.max(100)constraint for a topic. Add a passing case with"T".repeat(100)and a rejected case with"T".repeat(101).🤖 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 `@backend/tests/sessionValidator.maxLength.unit.test.js` around lines 91 - 100, Add tests in the “accepts role and experience at exact boundaries” area for the topicsToFocus item length: verify a topic of 100 characters passes validation and a topic of 101 characters is rejected, using the existing request/response helpers and assertions.
🤖 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.
Nitpick comments:
In `@backend/tests/flashcardValidator.maxLength.unit.test.js`:
- Around line 70-78: Update the request in the exact-boundary test for
validateCreateFlashcard to include category set to a 100-character value using
the existing repeat pattern. Keep the question and answer boundary values and
assertions unchanged.
In `@backend/tests/sessionValidator.maxLength.unit.test.js`:
- Around line 91-100: Add tests in the “accepts role and experience at exact
boundaries” area for the topicsToFocus item length: verify a topic of 100
characters passes validation and a topic of 101 characters is rejected, using
the existing request/response helpers and assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 48e9dd82-a434-45d7-8aae-8879cf293765
📒 Files selected for processing (4)
backend/Input_validators/ValidateFlashcard.jsbackend/Input_validators/ValidateSession.jsbackend/tests/flashcardValidator.maxLength.unit.test.jsbackend/tests/sessionValidator.maxLength.unit.test.js
Summary of What Has Been Done
Added
.max()guards to all string fields increateSessionSchemainbackend/Input_validators/ValidateSession.js:role: max 200 charactersexperience: max 50 charactersdescription: max 2000 characterstopicsToFocus[]: max 100 characters per topicquestion[].question: max 5000 charactersquestion[].answer: max 10000 charactersChanges Made
backend/Input_validators/ValidateSession.js: Added.max()Zod validatorsbackend/tests/sessionValidator.maxLength.unit.test.js: 8 unit tests covering max-length boundary casesImpact it Made
Closes #1402
Note: Please assign this PR to the
tmdeveloper007account.Looks good to me. Ready to merge.