mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
Add backend unit test framework and modularize settings UI
Introduced a Vitest-based backend unit testing framework with supporting scripts, helpers, and GitHub Actions integration. Refactored the admin settings page to a modular architecture, splitting monolithic logic into feature-specific tabs and hooks for improved maintainability and testability. Updated documentation to reflect the new testing setup and settings architecture, and added new dependencies for testing utilities.
This commit is contained in:
@@ -66,6 +66,9 @@ External integrations: Plex (auth + library), Prowlarr/Jackett (indexers), qBitt
|
||||
**Deployment:**
|
||||
- [deployment/docker.md](deployment/docker.md) - Docker Compose, volumes, env vars
|
||||
|
||||
**Testing:**
|
||||
- [testing.md](testing.md) - Backend unit tests, scripts
|
||||
|
||||
## Development Phases
|
||||
✅ Phase 1: Foundation (auth, database, setup wizard)
|
||||
✅ Phase 2: User features (discovery, requests, dashboard)
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
## Configuration & Setup
|
||||
- **First-time setup wizard** → [setup-wizard.md](setup-wizard.md)
|
||||
- **Settings management, encryption** → [backend/services/config.md](backend/services/config.md)
|
||||
- **Settings UI (Plex, Prowlarr, paths)** → [settings-pages.md](settings-pages.md)
|
||||
- **Settings UI (modular architecture, all tabs)** → [settings-pages.md](settings-pages.md)
|
||||
- **Settings architecture refactoring (Jan 2026)** → [settings-pages.md](settings-pages.md#architecture-refactored-jan-2026)
|
||||
- **Setup middleware & status check** → [backend/middleware.md](backend/middleware.md)
|
||||
- **Environment variables, PUBLIC_URL, OAuth configuration** → [backend/services/environment.md](backend/services/environment.md)
|
||||
|
||||
@@ -81,6 +82,9 @@
|
||||
- **Environment variables, volumes** → [deployment/docker.md](deployment/docker.md)
|
||||
- **Database setup (Prisma), migrations** → [deployment/docker.md](deployment/docker.md)
|
||||
|
||||
## Testing
|
||||
- **Backend unit test framework, scripts** [testing.md](testing.md)
|
||||
|
||||
## Feature-Specific Lookups
|
||||
**"How do I add a new audiobook?"** → [integrations/audible.md](integrations/audible.md) (scraping), [phase3/README.md](phase3/README.md) (automation)
|
||||
**"How do torrent downloads work?"** → [phase3/qbittorrent.md](phase3/qbittorrent.md), [backend/services/jobs.md](backend/services/jobs.md)
|
||||
|
||||
@@ -390,6 +390,22 @@ Personalized audiobook discovery using OpenAI/Claude APIs. Admin configures AI p
|
||||
- Consistent with recommendations endpoint filtering behavior
|
||||
- Files updated: `src/app/api/bookdate/generate/route.ts:147-157`
|
||||
|
||||
**8. Test Connection with Bad Custom LLM Credentials Logs User Out**
|
||||
- Issue: Testing custom LLM connection with invalid credentials causes user to be logged out instead of showing error
|
||||
- User Experience: "When I test connection with wrong API key, I get logged out of ReadMeABook instead of seeing an error message"
|
||||
- Cause: Custom LLM provider returns 401 Unauthorized for invalid credentials
|
||||
- Test-connection endpoint passed through external service's 401 status code
|
||||
- `fetchWithAuth()` utility intercepts ALL 401 responses, assuming they indicate expired user session
|
||||
- Triggers automatic token refresh, then logout if refresh fails or still 401
|
||||
- User logged out of application when only external service credentials were invalid
|
||||
- Fix: Return 400 Bad Request instead of passing through external service status codes
|
||||
- Changed lines 196, 387 in `src/app/api/bookdate/test-connection/route.ts`
|
||||
- Now returns `{ status: 400 }` for all custom provider connection failures
|
||||
- Reserve 401 status exclusively for application authentication issues
|
||||
- External service credential failures are client errors (400), not auth errors (401)
|
||||
- Added tests to verify 401 from external provider returns 400 to client
|
||||
- Files updated: `src/app/api/bookdate/test-connection/route.ts:190-197,382-389`, `tests/api/bookdate-test-connection.routes.test.ts:254-294`
|
||||
|
||||
## Related
|
||||
|
||||
- Full requirements: [features/bookdate-prd.md](bookdate-prd.md)
|
||||
|
||||
@@ -1,9 +1,67 @@
|
||||
# Settings Pages
|
||||
|
||||
**Status:** ✅ Implemented
|
||||
**Status:** ✅ Implemented | ♻️ Refactored (Jan 2026)
|
||||
|
||||
Single tabbed interface for admins to view/modify system configuration post-setup with mandatory validation before saving.
|
||||
|
||||
## Architecture (Refactored Jan 2026)
|
||||
|
||||
**Original:** Monolithic 2,971-line component
|
||||
**Current:** Modular architecture with 89% code reduction (2,971 → 325 lines)
|
||||
|
||||
**Structure:**
|
||||
```
|
||||
src/app/admin/settings/
|
||||
├── page.tsx # Shell component (325 lines)
|
||||
├── lib/
|
||||
│ ├── types.ts # Shared TypeScript interfaces
|
||||
│ └── helpers.ts # Business logic (206 lines)
|
||||
├── hooks/
|
||||
│ └── useSettings.ts # Global settings hook
|
||||
└── tabs/ # Feature modules
|
||||
├── LibraryTab/ # Plex/Audiobookshelf config
|
||||
│ ├── LibraryTab.tsx
|
||||
│ ├── useLibrarySettings.ts
|
||||
│ ├── PlexSection.tsx
|
||||
│ ├── AudiobookshelfSection.tsx
|
||||
│ └── index.ts
|
||||
├── AuthTab/ # Authentication (OIDC + Manual)
|
||||
│ ├── AuthTab.tsx
|
||||
│ ├── useAuthSettings.ts
|
||||
│ ├── OIDCSection.tsx
|
||||
│ ├── RegistrationSection.tsx
|
||||
│ ├── PendingUsersTable.tsx
|
||||
│ └── index.ts
|
||||
├── IndexersTab/ # Prowlarr/indexers
|
||||
│ ├── IndexersTab.tsx
|
||||
│ ├── useIndexersSettings.ts
|
||||
│ └── index.ts
|
||||
├── DownloadTab/ # qBittorrent/SABnzbd
|
||||
│ ├── DownloadTab.tsx
|
||||
│ ├── useDownloadSettings.ts
|
||||
│ └── index.ts
|
||||
├── PathsTab/ # Directory paths
|
||||
│ ├── PathsTab.tsx
|
||||
│ ├── usePathsSettings.ts
|
||||
│ └── index.ts
|
||||
├── EbookTab/ # E-book sidecar
|
||||
│ ├── EbookTab.tsx
|
||||
│ ├── useEbookSettings.ts
|
||||
│ └── index.ts
|
||||
└── BookDateTab/ # AI recommendations
|
||||
├── BookDateTab.tsx
|
||||
├── useBookDateSettings.ts
|
||||
└── index.ts
|
||||
```
|
||||
|
||||
**Benefits:**
|
||||
- Single Responsibility: Each tab manages its own state/logic
|
||||
- Testability: Individual tabs can be unit tested
|
||||
- Maintainability: Changes to one feature don't affect others
|
||||
- Performance: Lazy loading possible (future optimization)
|
||||
- Reusability: Custom hooks can be used elsewhere
|
||||
- Code Quality: Follows React best practices
|
||||
|
||||
## Sections
|
||||
|
||||
1. **Plex** - URL, token (masked), library ID, Audible region, filesystem scan trigger toggle
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# Testing
|
||||
|
||||
**Status:** ⏳ In Progress | Backend unit testing framework (Vitest)
|
||||
|
||||
## Overview
|
||||
Unit tests for backend logic with isolated mocks (Prisma, integrations, queue).
|
||||
|
||||
## Key Details
|
||||
- **Runner:** Vitest (`vitest.config.ts`, Node environment)
|
||||
- **Setup:** `tests/setup.ts` sets `NODE_ENV=test`, `TZ=UTC`, blocks unmocked fetch
|
||||
- **Helpers:** `tests/helpers/prisma.ts`, `tests/helpers/job-queue.ts`
|
||||
- **GitHub Actions:** Manual workflow `.github/workflows/manual-tests.yml` runs `npm test`
|
||||
- **Coverage:** `npm run test:coverage` (reports in `coverage/`)
|
||||
- **Scope:** Backend unit tests only; no real network or services
|
||||
|
||||
## API/Interfaces
|
||||
```
|
||||
npm run test
|
||||
npm run test:watch
|
||||
npm run test:coverage
|
||||
```
|
||||
|
||||
## Critical Issues
|
||||
- API route unit tests are incomplete; add route-level mocks before enforcing coverage.
|
||||
|
||||
## Related
|
||||
- [backend/services/jobs.md](backend/services/jobs.md)
|
||||
- [backend/services/scheduler.md](backend/services/scheduler.md)
|
||||
Reference in New Issue
Block a user