gronod
|
7d3e6e6a47
|
test: add integration and unit tests for dashboard, emby, sonarr, radarr, sabnzbd routes
Build and Push Docker Image / build (push) Successful in 39s
Docs Check / Markdown lint (push) Successful in 45s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 1m12s
CI / Security audit (push) Successful in 1m30s
CI / Tests & coverage (push) Failing after 1m39s
Docs Check / Mermaid diagram parse check (push) Successful in 1m59s
- tests/unit/dashboard.test.js: 58 unit tests covering all 12 pure helper
functions in dashboard.js (sanitizeTagLabel, tagMatchesUser, getCoverArt,
extractAllTags, extractUserTag, getImportIssues, getSonarrLink, getRadarrLink,
canBlocklist, extractEpisode, gatherEpisodes, buildTagBadges)
- tests/integration/dashboard.test.js: 35 integration tests for
/user-downloads (SAB+Sonarr, SAB+Radarr, qBit, showAll, paused queue,
history matching, importIssues, wrong-user filtering), /status (admin guard,
webhook check, failure handling), /webhook-metrics, /cover-art (all
validation/proxy paths), /blocklist-search (guards, Sonarr, Radarr, failure)
- tests/integration/emby.test.js: 13 integration tests covering all 4 Emby
routes (sessions, users, users/:id, session/:id/user) with auth guard,
happy path, and upstream failure cases
- tests/integration/arrRoutes.test.js: 64 integration tests for Sonarr +
Radarr (queue, history, series/movies, notifications CRUD, /test, /schema,
/sofarr-webhook create+update+missing-config+failure) and SABnzbd (queue,
history with custom params)
- vitest.config.js: raise global coverage thresholds (statements/functions/
lines 20->55, branches 8->40) to reflect improved coverage
(62.5% stmts, 42.6% branches, 64.1% funcs, 65.6% lines)
- tests/README.md: document new test files and update coverage table
|
2026-05-20 21:37:57 +01:00 |
|
gronod
|
5fd55b4e1a
|
test: add comprehensive test suite (115 tests, Vitest + supertest + nock)
Build and Push Docker Image / build (push) Successful in 49s
CI / Security audit (push) Successful in 1m23s
CI / Tests & coverage (push) Failing after 2m13s
Framework:
- Vitest v4 as test runner (fast ESM/CJS support, V8 coverage built-in)
- supertest for integration tests against createApp() factory
- nock for HTTP interception (works with CJS require('axios'), unlike vi.mock)
New files:
- vitest.config.js — test config: node env, isolate, V8 coverage, per-file thresholds
- tests/setup.js — isolated DATA_DIR per worker, SKIP_RATE_LIMIT, console suppression
- tests/README.md — approach, structure, design decisions
- server/app.js — testable Express factory (extracted from index.js side-effects)
Unit tests (91 tests):
- tests/unit/sanitizeError.test.js — secret redaction: apikey, token, bearer, basic-auth URLs
- tests/unit/config.test.js — JSON array + legacy single-instance config parsing
- tests/unit/requireAuth.test.js — valid/invalid/tampered cookies, schema validation
- tests/unit/verifyCsrf.test.js — double-submit pattern, timing-safe compare, safe methods
- tests/unit/qbittorrent.test.js — formatBytes, formatEta, mapTorrentToDownload state map
- tests/unit/tokenStore.test.js — store/get/clear lifecycle, TTL expiry, atomic disk write
Integration tests (24 tests):
- tests/integration/health.test.js — /health and /ready endpoints
- tests/integration/auth.test.js — full login/logout/me/csrf flows, input validation,
cookie attributes, no token leakage, Emby mock via nock
Production code changes (minimal, no behaviour change):
- server/routes/auth.js: EMBY_URL captured at request-time (not module load) for testability
- server/routes/auth.js: loginLimiter max → Number.MAX_SAFE_INTEGER when SKIP_RATE_LIMIT set
- server/utils/sanitizeError.js: fix HEADER_PATTERN to redact full line (not just first token)
CI:
- .gitea/workflows/ci.yml: add parallel 'test' job (npm run test:coverage, artifact upload)
- package.json: add test/test:watch/test:coverage/test:ui scripts
- .gitignore: add coverage/
|
2026-05-17 07:45:33 +01:00 |
|