Skip to content

Add a contract test asserting API routes conform to the apiContracts schemas #775

Description

@1nonlypiece

📌 Description

src/lib/schemas/apiContracts.ts declares the response schemas for the public
API, and src/lib/backend/apiResponse.ts is the standard envelope. There are
per-route tests, but no single contract test that parses representative
responses from the read routes through the apiContracts schemas to catch
breaking shape changes.

Goal: add a schema-contract test that validates real handler responses
against the declared apiContracts schemas.

🎯 Requirements and Context

  • For each covered read route (e.g. commitments list/detail, marketplace
    listings, protocol constants), call the handler and safeParse the body with
    its apiContracts schema; assert success.
  • Assert the standard success envelope (success: true, data) and the error
    envelope shape for a forced error.
  • Centralize a route→schema mapping so adding a route is a one-line change.
  • Mock data sources consistently with tests/api/helpers.ts.

🛠️ Suggested Execution

1. Fork the repo and create a branch

git checkout -b test/api-contract-schemas

2. Implement changes

  • Add tests/api/contract-schemas.test.ts (Vitest) importing schemas from
    src/lib/schemas/apiContracts.ts.

3. Test and commit

  • Run the repo suite: pnpm test
  • Edge cases: error envelope, optional/nullable fields, empty collections.

Example commit message

test: contract-test API routes against apiContracts schemas

✅ Guidelines

  • Minimum 95% test coverage on the schemas/envelope under test.
  • Clear, reviewer-friendly test names.
  • Timeframe: 96 hours.

🏷️ Labels

type-testing · area-frontend · MAYBE REWARDED · GRANTFOX OSS ·
OFFICIAL CAMPAIGN

💬 Community & Support

  • Join the CommitLabs contributor Discord: https://discord.gg/WV7tdYkJk
  • Please introduce yourself before you start so we can avoid duplicate work.

Metadata

Metadata

Labels

GRANTFOX OSSGrantFox open-source campaignMAYBE REWARDEDEligible for GrantFox rewardOFFICIAL CAMPAIGNOfficial GrantFox campaign issueStellar WaveIssues in the Stellar wave programarea-frontendFrontend / UI worktype-testingTests and test coverage

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions