Skip to content

feat: add comprehensive test suite and CI workflow#71

Open
AdityaAsopa wants to merge 7 commits intoisro:masterfrom
AdityaAsopa:feat/api-tests
Open

feat: add comprehensive test suite and CI workflow#71
AdityaAsopa wants to merge 7 commits intoisro:masterfrom
AdityaAsopa:feat/api-tests

Conversation

@AdityaAsopa
Copy link

Summary

Adds a Jest-based test suite covering all API handlers, the stats endpoint, individual resource endpoints, and data integrity — plus a CI workflow that runs on every PR.

Test coverage

API handler tests (tests/api/)

Collection endpoints (spacecrafts, launchers, customer_satellites, centres, spacecraft_missions):

  • Returns 200 with correct Content-Type: application/json
  • Returns correct wrapper key and record count with no filters
  • Filter behaviour: case-insensitive, composable (AND logic), unknown params ignored, empty array (not 404) when no matches

Stats endpoint (tests/api/stats.test.js):

  • All top-level sections present (totals, spacecraft_missions, spacecrafts, etc.)
  • Every distribution count sums to its collection total — mathematically verifies nothing is hardcoded
  • total_mass_kg is a positive number

Individual resource endpoints (tests/api/spacecrafts-id.test.js, spacecraft_missions-id.test.js):

  • Valid ID returns the correct record
  • Non-existent ID → 404
  • Non-integer ID → 400
  • _links.self always present; _links.mission / _links.spacecraft present when a match exists
  • Mission record has all 17 normalized schema fields

Data integrity tests (tests/data/integrity.test.js)

These act as a regression guard — they fail if a scraper update or manual edit silently corrupts the normalized schema:

  • All IDs are unique positive integers
  • No trailing whitespace in name fields
  • All non-null dates match ISO 8601 (YYYY-MM-DD)
  • All non-null numeric fields (mass_kg, power_watts, etc.) are positive numbers
  • status and orbit_type constrained to defined enums
  • Country names are title case (regression guard against all-caps normalization breaking)
  • centres.json uses lowercase field names (place, state — not Place, State)
  • Mass fields cannot contain string values (catches "values in wrong fields" class of errors)

CI workflow (.github/workflows/test.yml)

Runs on every PR and every push to master:

  1. npm test — Jest suite must pass
  2. npm run validate — JSON Schema validation must pass

Both gates must be green for CI to pass.

Design decisions

  • No HTTP server needed — handlers are tested directly as async functions with a minimal mockReq/mockRes helper. Fast, no ports, no teardown.
  • Zero runtime impactjest is a devDependency only
  • Test counts are pinned to current data (113, 64, 75, etc.) — this is intentional. If a scraper adds or removes records, the tests will flag it for human review rather than silently passing.

Notes

This PR cherry-picks all feature commits from PRs #65#70 so the tests are self-contained. As those PRs merge individually into master, this branch can be rebased cleanly — the test files themselves are net-new additions with no conflicts.

Test plan

  • npm install && npm test — all tests pass
  • npm run validate — all schemas pass
  • CI workflow triggers on this PR itself and goes green

AdityaAsopa and others added 7 commits March 12, 2026 15:17
The spacecraft_missions data had deeply inconsistent schemas — mass appeared
as 'weight', 'lift-off_mass', 'spacecraft_mass', 'mass_at_lift-off' and
5 other variants; dates ranged from 'April 19, 1975' to '22 October 2008'
to '26-05-1999' across 15+ formats; KALPANA-1 had mission_life stored in
the 'mission' field as '7 Years'; and TES appeared as a duplicate entry.
spacecrafts.json had only id+name for 113 records. launchers.json had
only id for 81 records. customer_satellites.json mixed 'GERMANY' with
'Germany' and 'UK' with 'UNITED KINGDOM'.

This commit introduces scripts/normalize_data.py — an idempotent pipeline
that parses all date formats to ISO 8601, extracts numeric mass_kg and
power_watts from free-text fields (handling edge cases like '15 Sq.m Solar
Array generating 1360W'), classifies orbits (LEO/SSO/GEO/Lunar/Failed),
infers mission status from launch date + mission life, and normalizes
country names. The scraper was re-run against isro.gov.in and the fresh
data is merged with existing records — no data is lost, only enriched.

All 5 data files now have consistent, documented schemas. spacecrafts are
enriched with launch date, vehicle, orbit type, and status from missions.
Launchers are classified into 8 vehicle families. All API endpoints remain
backward-compatible — same URLs, same structure, just cleaner data.

API handlers: removed unused 'fs' imports, fixed misleading variable names
(customer_satellites.js loaded data into a var called 'launchers'), added
Content-Type: application/json headers, and sanitized error responses.
Root endpoint now returns a JSON directory of all available endpoints.
Returns aggregate statistics computed at runtime from the five data
collections: record counts, mission status distribution, orbit type
breakdown, mission type breakdown, spacecraft status, customer satellite
country distribution and total mass, and launcher vehicle family counts.

All values derived directly from the JSON data files — nothing hardcoded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Each collection endpoint now accepts filter parameters:
- /api/spacecrafts?status=active&orbit_type=GEO&mission_type=Communication&launch_vehicle=PSLV
- /api/launchers?vehicle_family=PSLV
- /api/customer_satellites?country=Germany&launcher=PSLV-C37
- /api/centres?state=Karnataka
- /api/spacecraft_missions?status=active&orbit_type=SSO&mission_type=Remote+Sensing&launch_site=SDSC+SHAR

Filters are case-insensitive and composable — multiple params narrow
results. Unknown params are ignored. Empty array returned (not 404)
when filters match no records. No changes to existing response shape
when called without params.
Adds /api/:resource/:id endpoints for all five collections:
- GET /api/spacecrafts/:id
- GET /api/launchers/:id
- GET /api/customer_satellites/:id
- GET /api/centres/:id
- GET /api/spacecraft_missions/:id

Returns the matching record directly (not wrapped), 404 if not found,
400 if ID is not a valid integer. No new data added — reads directly
from existing normalized JSON files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
/api/spacecrafts/:id now includes a _links object:
  - _links.self: canonical URL for the spacecraft
  - _links.mission: URL to the matching spacecraft_missions record (when available)

/api/spacecraft_missions/:id now includes a _links object:
  - _links.self: canonical URL for the mission
  - _links.spacecraft: URL to the matching spacecrafts record (when available)

Cross-links are resolved by case-insensitive name matching between the
two datasets. All 64 mission records have a matching spacecraft entry.
No link is added when no match is found — no guessing.

Collection endpoints and other individual endpoints are unchanged.
Adds schema definitions and automated validation for all five data files:

Schemas (schemas/*.schema.json):
- Enforce required fields (id, name, status where applicable)
- Constrain orbit_type and status to known enum values
- Validate ISO 8601 date format on all date fields
- Require numeric types for mass_kg, power_watts, altitude_km
- Reject unknown fields (additionalProperties: false)

Validation script (scripts/validate_schemas.js):
- Zero-dependency beyond ajv (devDependency only, not runtime)
- Runs locally: npm run validate
- Exits 0 on success, 1 on any schema violation

CI workflow (.github/workflows/validate_data.yml):
- Triggers on any PR or push to master that touches data/ or schemas/
- Runs on ubuntu-latest with Node 20
- Fails the PR if any data file violates its schema

All five data files currently pass validation (confirmed pre-commit).
Adds Jest-based tests across three layers:

API handler tests (tests/api/):
- spacecrafts, launchers, customer_satellites, centres, spacecraft_missions
  - Correct HTTP status and Content-Type on all endpoints
  - Correct record counts returned with no filters
  - Filter behaviour: case-insensitive, composable, unknown params ignored,
    empty array (not 404) when no matches
- stats: all top-level sections present; every distribution sums to its
  collection total; total_mass_kg is positive
- spacecrafts/:id and spacecraft_missions/:id: valid ID returns record,
  non-existent ID returns 404, non-integer returns 400, _links present
  and correctly formatted

Data integrity tests (tests/data/integrity.test.js):
- All IDs are unique positive integers
- No trailing whitespace in name fields
- All non-null dates match ISO 8601 format
- All non-null numeric fields are positive numbers
- status and orbit_type constrained to known enums
- country names are title case (regression guard against all-caps)
- centres use lowercase field names (regression against Place/State)
- No values in wrong fields (mass field cannot be a string name)

CI (`.github/workflows/test.yml`):
- Runs on every PR and push to master
- Installs deps, runs jest, then runs schema validation
- Both must pass for CI to go green

Test runner: Jest 29 (devDependency only, zero runtime impact).
All tests pass against current normalized data.
AdityaAsopa added a commit to AdityaAsopa/isro_api that referenced this pull request Mar 12, 2026
- CHANGELOG.md: full project history (v1.0.0 → v1.1.0) documenting all
  7 PRs (isro#65isro#71) in Keep a Changelog format; Unreleased section for today's work
- index.html: complete rewrite — space-themed mission control dashboard;
  live Chart.js visualisations (orbit distribution, mission status, vehicle
  families, top countries by satellite count); animated counters fed from
  /api/stats; responsive star-field background; endpoint quick-reference cards
- style.css: full rewrite with CSS custom properties; dark space palette
  (#080818 bg, #06b8ee accent); responsive grid at 900 px and 600 px breakpoints
- api/timeline.js: GET /api/timeline — aggregates launch dates from
  spacecraft_missions, spacecrafts, and customer_satellites into a unified
  chronological event stream; supports ?date=MM-DD, ?month=YYYY-MM,
  ?year=YYYY, ?range=YYYY,YYYY query params
- isro_api_plan.md: big-picture vision document (10 major platform moves)
- social_posts.md: LinkedIn posts and X thread for all 7 PRs
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.

1 participant