Skip to content

test: create api fixture validator#605

Open
davidcreated wants to merge 1 commit into
StellaBridge:mainfrom
davidcreated:feature/testing-api-fixture-validator
Open

test: create api fixture validator#605
davidcreated wants to merge 1 commit into
StellaBridge:mainfrom
davidcreated:feature/testing-api-fixture-validator

Conversation

@davidcreated

Copy link
Copy Markdown

Summary

Implements an API Fixture Validator that checks the JSON fixtures under e2e/fixtures/ against Zod schemas mirroring the current API/domain shapes (the canonical types in frontend/src/types). This catches fixture drift — fields added, removed, renamed, or retyped in the API but not in the fixtures — before stale fixtures silently weaken the tests.

Closes #561

What's included

  • Validator core (backend/src/testing/fixtureValidator/)
    • schemas.ts — Zod schemas mirroring Asset, HealthScore, HealthFactors, Bridge, and the fixture-file envelopes.
    • registry.ts — maps each fixture file to the schema describing its API shape.
    • validator.ts — reads, parses, and validates fixtures; emits readable, path-pointed diffs (e.g. USDC.factors.liquidityDepth).
    • format.ts — CI-friendly text report.
  • Severity model
    • error — missing/mistyped required field, invalid enum, unreadable/invalid JSON → fails CI.
    • warning — a property no longer part of the current API shape → fails only under --strict.
  • CLInpm --workspace=backend run fixtures:validate (supports --json and --strict), exits non-zero on drift.
  • CI — runs in the node-ci job right after lint.
  • Unit testsbackend/tests/testing/fixtureValidator.test.ts (validates every registered fixture + covers missing field, wrong type, bad enum, unexpected property, and nested record paths).
  • Docsbackend/docs/FIXTURE_VALIDATION.md covering how to run it, the update workflow when the API changes, and how to add a new fixture.

Drift fixed in this PR

While building the validator it flagged real drift: e2e/fixtures/asset-health.json was missing the required HealthScore.lastUpdated field. Fixed so the committed fixtures match the current shape.

Verification

  • npm --workspace=backend run lint
  • npm --workspace=backend run build
  • npm --workspace=backend run fixtures:validatePASS
  • npm --workspace=backend run test -- tests/testing → 9/9 passing ✅
  • Confirmed the validator fails with readable diffs + exit code 1 when a fixture is intentionally broken.

How to extend

Add a fixture file, add a schema to schemas.ts, and register it in registry.ts — it's then covered by both the CLI check and the test suite.

Add a fixture validator that checks the JSON fixtures under e2e/fixtures
against Zod schemas mirroring the current API/domain shapes
(frontend/src/types), catching fixture drift before it reaches tests.

- backend/src/testing/fixtureValidator: schemas, registry, validator, and
  readable diff formatting; classifies findings as errors (missing/mistyped
  required fields, bad enums, invalid JSON) or warnings (fields no longer in
  the API shape)
- backend/scripts/validate-fixtures.ts CLI with --json and --strict, exits
  non-zero on drift; wired up as the "fixtures:validate" npm script
- Run in CI (node-ci job) right after lint, and as a backend unit test
- Fix the stale asset-health fixture, which was missing the required
  HealthScore.lastUpdated field
- Document the check and the fixture update workflow in
  backend/docs/FIXTURE_VALIDATION.md

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create API Fixture Validator

1 participant