test: comprehensive Rust tests + real-backend integration tests #12

Merged
gabogg merged 3 commits from feat/desktop-tests into dev 2026-06-23 17:40:03 +00:00
Owner

Rust tests (10 new, runs in CI via cargo test)

  • Refactored HTTP logic into standalone api.rs module — no Tauri dependency
  • Tests: URL building (with/without query, trailing slashes), base URL resolution (configured → env → default), token extraction, serde roundtrip
  • Existing auth tests: serialization, config defaults, stored auth lifecycle

JS integration tests (6 tests, ~650ms)

  • Real Spring backend — test-helpers.sh starts mvn spring-boot:run with H2 in-memory test DB on port 14000
  • Tests: login with valid credentials, invalid login rejection, GET /auth/me, GET /api/items, GET /api/branches, unauthenticated rejection
  • Isolated config via vitest.integration.config.js — unit tests and integration tests never mix

Unit tests still pass (13/13, ~100ms)

CI workflow updated

  • New backend-integration job: installs Java 21, spins up backend, runs integration + E2E tests
  • Only triggers on PRs

Files changed

  • desktop/src-tauri/src/api.rs — new pure-Rust HTTP API module
  • desktop/src-tauri/src/commands.rs — delegates to api.rs
  • desktop/src-tauri/src/lib_test.rs — additional Rust tests
  • desktop/src/api.integration.test.js — 6 real-backend integration tests
  • desktop/test-helpers.sh — backend lifecycle manager
  • desktop/vitest.integration.config.js — separate vitest config
  • .github/workflows/desktop.yml — added integration job
### Rust tests (10 new, runs in CI via `cargo test`) - Refactored HTTP logic into standalone `api.rs` module — no Tauri dependency - Tests: URL building (with/without query, trailing slashes), base URL resolution (configured → env → default), token extraction, serde roundtrip - Existing auth tests: serialization, config defaults, stored auth lifecycle ### JS integration tests (6 tests, ~650ms) - **Real Spring backend** — `test-helpers.sh` starts `mvn spring-boot:run` with H2 in-memory test DB on port 14000 - Tests: login with valid credentials, invalid login rejection, GET /auth/me, GET /api/items, GET /api/branches, unauthenticated rejection - Isolated config via `vitest.integration.config.js` — unit tests and integration tests never mix ### Unit tests still pass (13/13, ~100ms) ### CI workflow updated - New `backend-integration` job: installs Java 21, spins up backend, runs integration + E2E tests - Only triggers on PRs ### Files changed - `desktop/src-tauri/src/api.rs` — new pure-Rust HTTP API module - `desktop/src-tauri/src/commands.rs` — delegates to api.rs - `desktop/src-tauri/src/lib_test.rs` — additional Rust tests - `desktop/src/api.integration.test.js` — 6 real-backend integration tests - `desktop/test-helpers.sh` — backend lifecycle manager - `desktop/vitest.integration.config.js` — separate vitest config - `.github/workflows/desktop.yml` — added integration job
Rust (api.rs):
- Refactored HTTP logic into testable api module (no Tauri deps)
- 10 unit tests: URL building, base URL resolution, token extraction
- auth.rs tests: serialization, config defaults, roundtrip

JS integration tests (api.integration.test.js):
- 6 tests against real Spring backend with H2 test DB
- Auth flow: login (valid + invalid), GET /auth/me, CRUD endpoints
- Isolated from unit tests via vitest.integration.config.js

Test runner (test-helpers.sh):
- Starts Spring backend in test profile on port 14000
- Waits for health check, runs integration tests, stops gracefully
- Works as standalone script or sourced for modular use

CI (desktop.yml):
- Added backend-integration job: installs Java 21, starts backend,
  runs vitest integration + Playwright E2E against live backend
- Only runs on PRs (10min timeout)

Test results:
- Unit: 13/13 (~100ms)
- Integration: 6/6 against real backend (~650ms)
- Build: 71KB JS + 7KB CSS

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
gabogg force-pushed feat/desktop-tests from ced6798d35 to 6f9b33548c 2026-06-23 16:54:31 +00:00 Compare
- Fix api.js BASE_URL: strip trailing /api from VITE_API_URL so
  paths like /api/items produce http://host/api/items (no double prefix)
- Fix api-invoke.js: add ReferenceError guard for process.env in browser
- Add httpFallback to api-invoke.js for browser/Tauri bridge commands
  (store_auth, get_stored_auth, clear_auth fall to localStorage)
- Add test:e2e:headed npm script for visual Playwright testing
- Fix CORS: test-helpers.sh now passes --app.cors-origin=$CORS_ORIGIN
  (defaults to http://localhost:1420 for Vite dev server)
- Update Playwright E2E to test full login + navigate all pages + logout

E2E verified: headed browser session completes login, visits all 9
CRUD pages, scanner, audit log, and returns to login screen.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Test suite (23.3s headed, 12/12 passing):

Login + Dashboard:
- Login form accepts credentials, dashboard shows stat cards
- All 7 entity pages render data tables with seed data
  (Branches, Departments, Categories, Items, Users, Bags)

Categories CRUD (only entity where generic inline form works):
- Create via UI modal, verify in table and via API
- Edit name, verify update in table and API
- Delete, verify removed from table and API

Scanner + Audit pages:
- Scanner page renders camera button and help text
- Audit log page renders entity selector and search

Bug fixes discovered during testing:
- getToken() was async causing "Bearer [object Promise]" header
- ListPage response parsing lacked `data` field support
- DashboardPage lacked `total` field support
- api-invoke.js lacked browser/http fallback for Tauri commands
- CORS needed explicit --app.cors-origin for dev server
- BASE_URL double-/api prefix stripping

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
PCivil/inventory-system!12
No description provided.