Skip to content

test: backend unit + functional and iOS model tests, run in CI - #6

Merged
restlessankyyy merged 3 commits into
mainfrom
test/backend-and-ios-suite
Jun 23, 2026
Merged

test: backend unit + functional and iOS model tests, run in CI#6
restlessankyyy merged 3 commits into
mainfrom
test/backend-and-ios-suite

Conversation

@restlessankyyy

Copy link
Copy Markdown
Owner

What

Adds an automated test suite for both halves of Voltpit and wires it into CI.

Backend (node:test run via tsx)

  • types.test.ts (unit): mph/kph conversion helpers and round-trip.
  • wsHub.test.ts (unit): broadcast to open clients, last vehicle_state replay on connect, status messages not replayed, client cleanup on close/error.
  • SimulatorSource.test.ts (unit): emission shape, primaryUnit passthrough (mph/kph), speedKph derivation, Stockholm route bounds, stop halts ticks. Mocked Math.random + fake timers for determinism.
  • server.functional.test.ts (functional): spawns the real server as a child process and exercises /health, the /stream WebSocket emitting a well-formed metric vehicle_state, and token-guarded auth (rejects missing/wrong tokens, accepts the right one).
  • Adds npm test script and excludes *.test.ts from the tsc build.

iOS (XCTest)

  • VehicleStateTests.swift: decodes the exact backend vehicle_state JSON contract (including parked/null fields) and verifies the UI-driving derived values (usesMetric, primarySpeed clamping, unitLabel). Adds a TeslaDashTests unit-test target and a TeslaDash scheme in project.yml.

CI

  • backend-ci: runs npm test after the tsc build.
  • ios-build: runs xcodebuild test on a dynamically resolved iPhone simulator after the build.

Results

  • Backend: 17 passing (cd backend && npm test).
  • iOS: 7 passing (xcodebuild test on the iPhone 17 Pro simulator).

Architecture impact

None. Test-only addition plus CI steps: no components, data flow, message contracts, or infra change, so the architecture docs are unchanged.

Backend (node:test via tsx):
- types.test.ts: mph/kph conversion helpers
- wsHub.test.ts: broadcast, last-state replay, client cleanup
- SimulatorSource.test.ts: emission shape and unit passthrough
- server.functional.test.ts: real server child process, /health,
  /stream metric payload, token-guarded auth
- add npm test script; exclude *.test.ts from the tsc build

iOS (XCTest):
- VehicleStateTests.swift: backend JSON contract decoding plus the
  derived UI values (usesMetric, primarySpeed, unitLabel)
- add TeslaDashTests unit-test target and TeslaDash scheme in project.yml
- backend-ci: add npm test after the tsc build
- ios-build: run xcodebuild test on an available iPhone simulator
node --test only expands the src/**/*.test.ts glob on Node 21+, so the
Node 20 runner failed to find the test files.
@restlessankyyy
restlessankyyy merged commit 2c2db7c into main Jun 23, 2026
3 of 4 checks passed
@restlessankyyy
restlessankyyy deleted the test/backend-and-ios-suite branch June 23, 2026 21:37
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