Skip to Content
Welcome to RitoSwap's documentation!
dAppVitestAPI Contract QA

API Contract & OpenAPI Testing

This page documents the RitoSwap-specific contract test suite in:

app/api/__contract__/contract.test.ts

It is focused on the four public, token-gate–related endpoints actually used in this repo:

  • GET /api/nonce
  • POST /api/gate-access
  • GET /api/token-status/{tokenId}
  • POST /api/form-submission-gate

All tests validate against the project’s OpenAPI spec:

public/openapi.json
💡

These tests are not generic examples. They encode the exact response shapes, status codes, and error formats that RitoSwap promises at its token-gate surface area.

What these tests cover

The contract suite models RitoSwap’s public contract at the HTTP layer.

        • contract.test.ts
    • openapi.json

At a high level, contract.test.ts defines:

  • Types dedicated to this file:
    • HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
    • ContractTestCase with name, status, and response shape
    • ContractTest grouping a path, method, and testCases[]
  • A CONTRACT_TESTS array with hand-authored examples for each RitoSwap endpoint.
  • A coerceMessageEnumIfPresent() helper tuned to the /api/form-submission-gate success schema.
  • A describe('API Contract Tests') block that:
    • Hydrates OpenAPITestValidator via getOpenAPIValidator() from @/e2e/supertest/openapi-validator.
    • Iterates the RitoSwap endpoints only and calls validator.validateResponse(...).
    • Runs two meta-tests to track coverage across all paths and response codes in openapi.json.

No route handlers are imported. This file is purely about matching RitoSwap’s documented contract.

Summary

  • This suite is tailored specifically to RitoSwap’s token-gate endpoints, not a generic example.
  • It encodes the exact success and error shapes for:
    • /api/nonce
    • /api/gate-access
    • /api/token-status/{tokenId}
    • /api/form-submission-gate
  • It uses the same OpenAPI validator as your supertest E2E flow, but runs entirely in Vitest.
  • Meta-tests and generateContractCoverage() give you a quick read on whether docs and contract tests are still aligned with the public surface area of the project.