feat(petition): add server-side validation and unit tests (#28)#29
Open
aaronaco wants to merge 5 commits intobettergovph:mainfrom
Open
feat(petition): add server-side validation and unit tests (#28)#29aaronaco wants to merge 5 commits intobettergovph:mainfrom
aaronaco wants to merge 5 commits intobettergovph:mainfrom
Conversation
Contributor
Author
|
The CI lint check is failing due to pre-existing formatting issues in files unrelated to this PR. My changes are properly formatted. Should I fix these in this PR or should they be addressed separately? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds comprehensive server-side validation for petition creation and updates, along with a complete unit test suite.
Closes #28
AI-Assisted Work Disclosure
This PR was developed with assistance from an AI tool for:
Type of Change
Changes
1. Server-Side Validation (Zod v4)
Added validation schemas in
functions/_shared/schemas.ts:createPetitionSchema- Validates petition creation requestsupdatePetitionSchema- Validates petition update requestsformatZodError- Formats Zod validation errors for API responsesImplemented validation in API handlers:
POST /api/petitions- Validates creation requests with detailed error messagesPUT /api/petitions/[id]- Validates update requests with partial update supportValidation Rules:
2. Unit Tests (Vitest)
Created test suite with 42 tests total:
tests/unit/create-petition.test.ts(27 tests)tests/unit/update-petition.test.ts(13 tests)tests/unit/setup.test.ts(2 tests)Test Configuration:
vitest.config.ts:e2edirectory from Vitest (E2E tests use Playwright)3. Documentation
tests/README.md:Testing
pnpm test:unit # ✓ 42 tests passingTest Coverage:
Checklist