test: contract-test API routes against apiContracts schemas#896
Merged
1nonlypiece merged 1 commit intoJun 27, 2026
Merged
Conversation
|
@yunus-dev-codecrafter is attempting to deploy a commit to the 1nonly's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@yunus-dev-codecrafter Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
contract-testing the api routes against the schemas is exactly what we needed. in |
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.
closes #775
test: contract-test API routes against apiContracts schemas
Summary
Adds a schema-contract test (
tests/api/contract-schemas.test.ts) that validates real handler responses against the declaredapiContractsZod schemas, ensuring the API shape stays in sync with its contract definitions.Also fixes two schema/handler mismatches that the new test uncovered.
Changes
New file:
tests/api/contract-schemas.test.ts11 tests covering 5 read routes via a centralized
routeSchemaMap:GET /api/healthHealthResponseSchemaGET /api/commitmentsCommitmentsListResponseSchemaGET /api/commitments/[id]CommitmentDetailResponseSchemaGET /api/commitments/searchCommitmentSearchResponseSchemaGET /api/marketplace/listingsMarketplaceListingsResponseSchemaSuccess envelope (5 tests) — calls each handler, asserts
status === 200,success === true, andschema.safeParse(body).success === trueEmpty collections (3 tests) — verifies
[]items/data/listings still pass schema validationOptional/nullable fields (2 tests) — commitments with missing
complianceScore,currentValue,feeEarned, etc.; commitment detail withmaxLossPercent: nulland absentdrawdownPercent/tokenIdError envelope (1 test) — calls
GET /api/commitmentswithoutownerAddress, asserts 400 status andErrorBodySchema.safeParse(body).success === trueAdding a new route is a one-line addition to
routeSchemaMapAll mock data factories (
makeChainCommitment,makeChainCommitmentDetail,makeMarketplaceListing) are centralized and reusableFixed: schema-handler mismatches (caught by the new test)
src/lib/schemas/apiContracts.ts:HealthResponseSchema: changed fromdata: { status, timestamp }todata: { status, uptime, version }to match what the handler actually returnsCommitmentDetailSchema:drawdownPercentandtokenIdchanged from.optional()to.nullable().optional()to match the handler's?? nullpatterntests/api/contracts.test.ts: UpdatedHealthResponseSchemaunit tests to reflect the corrected schema shapeTest results
pnpm vitest run tests/api/contract-schemas.test.ts— 11/11 passedpnpm vitest run tests/api/contracts.test.ts— 70/70 passed (existing)pnpm vitest run tests/api/health.test.ts— 2/2 passed (existing)pnpm vitest run tests/api/commitment-search.test.ts— 51/51 passed (existing)pnpm run lint— no new errors from these changes