-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(test-utils): add custom response matchers for API error handling #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
Warning Rate limit exceeded@luxass has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 51 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (4)
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 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 |
🌏 Preview DeploymentsNote No deployable apps affected by changes in this PR. Built from commit: 🤖 This comment will be updated automatically when you push new commits to this PR. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Greptile SummaryAdded four custom Vitest matchers to
The matchers follow the existing pattern from Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant Matcher as Custom Matchers
participant Response as Response Object
participant Schema as Zod Schema
participant Error as ApiError
Note over Test,Matcher: Response Validation Flow
Test->>Matcher: expect(response).toMatchResponse(options)
Matcher->>Response: Check status code
Matcher->>Response: Check content-type header
Matcher->>Response: Validate cache-control
Matcher->>Response: Check custom headers
alt Error validation requested
Matcher->>Response: response.json()
Response-->>Matcher: ApiError object
Matcher->>Error: Validate status, message, timestamp
Matcher-->>Test: Pass/Fail with message
else Standard response
Matcher-->>Test: Pass/Fail with message
end
Note over Test,Matcher: Schema Validation Flow
Test->>Matcher: expect(data).toMatchSchema(options)
Matcher->>Schema: schema.safeParse(data)
Schema-->>Matcher: Validation result
alt Partial data check
Matcher->>Matcher: Compare expected properties
end
Matcher-->>Test: Pass/Fail with message
Note over Test,Matcher: API Error Validation Flow
Test->>Matcher: expect(response).toBeApiError(options)
Matcher->>Response: Verify status matches
Matcher->>Response: Check JSON content-type
Matcher->>Response: response.json()
Response-->>Matcher: ApiError object
Matcher->>Error: Validate structure
alt Message pattern provided
Matcher->>Error: Test message against pattern
end
Matcher-->>Test: Pass/Fail with message
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 3 comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces custom Vitest matchers for API response and schema validation testing, enhancing the test-utils package with three new matchers: toBeApiError, toBeHeadError, and toMatchResponse, along with a schema validation matcher toMatchSchema.
Key changes:
- Added schema validation matcher with support for partial data matching
- Added API error validation matchers with status code, content-type, and message verification
- Added HEAD request error matcher for validating error responses with proper content-length
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
packages/test-utils/src/matchers/vitest-setup.ts |
Registers the new matchers (toMatchSchema, toBeApiError, toBeHeadError, toMatchResponse) with Vitest |
packages/test-utils/src/matchers/types.d.ts |
Adds TypeScript type definitions for the new matchers to the Vitest Matchers interface |
packages/test-utils/src/matchers/schema-matchers.ts |
Implements toMatchSchema matcher for validating data against Zod schemas with optional partial data checking |
packages/test-utils/src/matchers/response-matchers.ts |
Implements three response validation matchers for API error handling, HEAD requests, and general response matching |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🔗 Linked issue
📚 Description
This PR adds a few new matchers.
Helps closing #420