Skip to content

Test Strategy

The project uses a four-layer test strategy: backend unit/smoke, frontend unit, end-to-end (Playwright), and k6 for performance/safety verification.

Backend

cd iqvflex/backend
npm test

node --test runs unit/integration tests across 5 files (ERP mapping, ERP auth, upsert, Go proxy, Go auth); then test/smoke.mjs boots a real Express application and verifies the core endpoints (health, error codes, 404) without MongoDB.

Frontend

cd dashboard
npm test

node --test runs unit tests verifying that normalization and format conversion logic behave identically to the legacy Node-RED implementation.

End-to-end (E2E)

cd dashboard && npm run build && npx vite preview --port 4173 &
cd iqvflex/backend && npm install
cd iqvflex/e2e && npm install && npx playwright install chromium
npm test

Verifies the full chain: browser → Node.js backend → (fake) Go Integration API → backend → browser. The MongoDB repository layer is mocked, so no running mongod is needed; the Go service is also a fake HTTP server started inside the test. Coverage: JSON/XML flows, error states not being lost, and no secrets present in the frontend bundle.

k6 (smoke and load testing)

k6 tests live under iqvflex/backend/test/k6/:

File Purpose
common.js Shared helpers, assertNonProductionTarget safety gate
smoke.js 1 VU / 1 iteration — no check should fail
load.js Controlled, non-aggressive load profile (default 5 VU)

Safety gate: tests can only target localhost / *.test / *.local / *staging* / *.internal addresses; running against a production address makes the test fail() immediately.

cd iqvflex/backend
npm install
K6_BASE_URL=http://127.0.0.1:3199 PORT=3199 node server.js &
k6 run test/k6/smoke.js

If K6_TEST_IDENTIFIER / K6_TEST_PASSWORD are provided, tryLogin() also attempts a real login; if not, this step is skipped — no fake production identity is generated.

In CI, the smoke test relies on the backend being able to start without a real MongoDB (see CI/CD).