Add comprehensive test coverage for API and Data protocol schemas#427
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…t-server) Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
|
This PR is very large. Consider breaking it into smaller PRs for easier review. |
| }); | ||
|
|
||
| // Get items | ||
| const itemsRequest = GetMetaItemsRequestSchema.parse({ |
Check notice
Code scanning / CodeQL
Unused variable, import, function or class Note test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
To fix the problem, we should remove the unused variable while still preserving any needed side effects from calling GetMetaItemsRequestSchema.parse. The simplest way is to call parse without assigning its return value, or, if we want to assert something about the parsed data, actually use the variable in an expectation.
The minimal, behavior-preserving change is to drop the const itemsRequest = binding and keep the parse call as a standalone statement. This maintains the validation side effect (throwing on invalid input) but eliminates the unused variable. The change is localized to packages/spec/src/api/protocol.test.ts around line 623, inside the "should support metadata discovery workflow" test. No new imports or definitions are needed.
| @@ -620,7 +620,7 @@ | ||
| }); | ||
|
|
||
| // Get items | ||
| const itemsRequest = GetMetaItemsRequestSchema.parse({ | ||
| GetMetaItemsRequestSchema.parse({ | ||
| type: 'object', | ||
| }); | ||
|
|
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive test coverage for 7 previously untested protocol schemas in the packages/spec repository. The changes include 344 new tests organized into:
Changes:
- API Protocol Tests (242 tests): OData v4 query syntax, ObjectStack RPC protocol, routing, REST API configuration, and saved views
- Data Protocol Tests (102 tests): Hook lifecycle events and data engine query/CRUD operations
- All tests follow Zod validation patterns with comprehensive coverage of success cases, error cases, defaults, and edge cases
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/spec/src/api/odata.test.ts | 64 tests validating OData v4 query parameters, filter operators, functions, response/error formats, and metadata schemas |
| packages/spec/src/api/protocol.test.ts | 50 tests covering ObjectStack RPC protocol discovery, metadata endpoints, CRUD operations, and batch operations |
| packages/spec/src/api/router.test.ts | 40 tests for route definitions, HTTP methods, path patterns, security, CORS, and routing configuration |
| packages/spec/src/api/rest-server.test.ts | 42 tests validating REST API config including CRUD endpoints, metadata, batch operations, and documentation settings |
| packages/spec/src/api/view-storage.test.ts | 46 tests for saved views (list/kanban/calendar/chart), layouts, visibility, and CRUD contracts |
| packages/spec/src/data/hook.test.ts | 45 tests covering hook lifecycle events, execution order, async/sync modes, error policies, and context schemas |
| packages/spec/src/data/data-engine.test.ts | 57 tests for data engine query options, filters, sorting, CRUD operations, aggregations, vector search, and batch requests |
|
|
||
| describe('HTTP Methods', () => { | ||
| it('should accept all HTTP methods', () => { | ||
| const methods: Array<z.infer<typeof HttpMethod>> = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']; |
There was a problem hiding this comment.
The variable z is used but not imported from 'zod'. The line uses Array<z.infer<typeof HttpMethod>> which will cause a runtime error. Either import z from 'zod', or simply remove the type annotation since TypeScript can infer the type from the array literal.
Overview
Adds test coverage for 7 previously untested protocol schemas in
packages/spec/src. Total: 344 new tests across API and Data protocols.Changes
API Protocol Tests (242 tests)
odata.test.ts(64 tests) - OData v4 query syntax, filters, operators, response/error formats, metadataprotocol.test.ts(50 tests) - ObjectStack RPC protocol: discovery, metadata, CRUD, batch operationsrouter.test.ts(40 tests) - Route definitions, categories, CORS, security, static mountsrest-server.test.ts(42 tests) - REST API config, CRUD endpoints, metadata/batch endpoint generationview-storage.test.ts(46 tests) - Saved views (list/kanban/calendar/chart), layouts, CRUD contractsData Protocol Tests (102 tests)
hook.test.ts(45 tests) - Hook lifecycle events, execution order, async/sync modes, error policiesdata-engine.test.ts(57 tests) - Query/insert/update/delete options, aggregations, vector search, batch operationsExample
All tests follow existing Zod validation patterns and cover success/error cases, defaults, edge cases, and real-world integration scenarios.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.