Skip to content

[Test] Add HTTP-layer test coverage for Fastify routes in apps/api #238

Description

@collinsezedike

Summary

apps/api has zero HTTP-layer tests. The Fastify route handlers (positions, deposit, withdraw, health) are only exercised end-to-end against a live network. Unit tests exist for SDK helpers, but nothing verifies that the route layer parses requests correctly, validates inputs, serialises responses, or returns the right HTTP status codes.

Motivation

Without HTTP-layer tests, a change to a route handler (wrong status code on error, missing field in response, broken input validation) ships silently. Fastify's inject API makes it possible to test routes without a real network -- the suite can run in CI with mocked SDK helpers.

Proposed Solution

Add a Vitest test file at apps/api/src/__tests__/routes.test.ts using fastify.inject to test each route:

  • GET /health -- 200 with expected body shape
  • GET /positions -- 200 with mocked SDK response; 400 on missing wallet param; 500 when SDK throws
  • POST /deposit -- 200 with mocked prepareSorobanTx; 400 on invalid body; 422 on simulation failure
  • POST /withdraw -- same shape as deposit

Mock @meridian/stellar-sdk-helpers at the module level so no Soroban RPC calls are made.

Scope

Field Value
Area api, testing
Protocol affected none (mocked)
Network n/a
Breaking change? No

Acceptance Criteria

  • apps/api/src/__tests__/routes.test.ts covers all four route groups
  • Tests run without a live RPC endpoint
  • pnpm test passes from the repo root

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAdds or modifies a REST endpoint in apps/apihardComplex implementation spanning multiple packages or involving Soroban contractstestingAdds or improves test coverage (unit, integration, or e2e)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions