- Add SetupService for detecting application setup completion - Create ApplicationFlowMiddleware to enforce setup auth main flow - Add setup processing endpoints (/api/auth/setup, /api/auth/setup/status) - Add Pydantic models for setup requests and responses - Integrate middleware into FastAPI application - Fix logging paths to use ./logs consistently - All existing templates (setup.html, login.html) already working
6.3 KiB
6.3 KiB
AniWorld Test Generation Checklist
This file instructs the AI agent on how to generate tests for the AniWorld application. All tests must be saved under src/tests/ and follow the conventions in .github/copilot-instructions.md. Use [ ] for each task so the agent can checkmark completed items.
📁 Test File Structure
- Place all tests under
src/tests/src/tests/unit/for component/unit testssrc/tests/integration/for API/integration testssrc/tests/e2e/for end-to-end tests
🧪 Test Types
- Component/Unit Tests: Test individual functions, classes, and modules.
- API/Integration Tests: Test API endpoints and database/external integrations.
- End-to-End (E2E) Tests: Simulate real user flows through the system.
📝 Test Case Checklist
1. Authentication & Security
- Unit: Password hashing (SHA-256 + salt)
- Unit: JWT creation/validation
- Unit: Session timeout logic
- API:
POST /auth/login(valid/invalid credentials) - API:
GET /auth/verify(valid/expired token) - API:
POST /auth/logout - Unit: Secure environment variable management
- E2E: Full login/logout flow
2. Health & System Monitoring
- API:
/healthendpoint - API:
/api/healthendpoint - API:
/api/health/system(CPU, memory, disk) - API:
/api/health/database - API:
/api/health/dependencies - API:
/api/health/performance - API:
/api/health/metrics - API:
/api/health/ready - Unit: System metrics gathering
3. Anime & Episode Management
- API:
GET /api/anime/search(pagination, valid/invalid query) - API:
GET /api/anime/{anime_id}(valid/invalid ID) - API:
GET /api/anime/{anime_id}/episodes - API:
GET /api/episodes/{episode_id} - Unit: Search/filter logic
4. Database & Storage Management
- API:
GET /api/database/info - API:
/maintenance/database/vacuum - API:
/maintenance/database/analyze - API:
/maintenance/database/integrity-check - API:
/maintenance/database/reindex - API:
/maintenance/database/optimize - API:
/maintenance/database/stats - Unit: Maintenance operation logic
5. Bulk Operations
- API:
/api/bulk/download - API:
/api/bulk/update - API:
/api/bulk/organize - API:
/api/bulk/delete - API:
/api/bulk/export - E2E: Bulk download and export flows
6. Performance Optimization
- API:
/api/performance/speed-limit - API:
/api/performance/cache/stats - API:
/api/performance/memory/stats - API:
/api/performance/memory/gc - API:
/api/performance/downloads/tasks - API:
/api/performance/downloads/add-task - API:
/api/performance/resume/tasks - Unit: Cache and memory management logic
7. Diagnostics & Logging
- API:
/diagnostics/report - Unit: Error reporting and stats
- Unit: Logging configuration and log file management
8. Integrations
- API: API key management endpoints
- API: Webhook configuration endpoints
- API: Third-party API integrations
- Unit: Integration logic and error handling
9. User Preferences & UI
- API: Theme management endpoints
- API: Language selection endpoints
- API: Accessibility endpoints
- API: Keyboard shortcuts endpoints
- API: UI density/grid/list view endpoints
- E2E: Change preferences and verify UI responses
10. CLI Tool
- Unit: CLI commands (scan, search, download, rescan, display series)
- E2E: CLI flows (progress bar, retry logic)
11. Miscellaneous
- Unit: Environment configuration loading
- Unit: Modular architecture components
- Unit: Centralized error handling
- API: Error handling for invalid requests
🛠️ Additional Guidelines
- Use
pytestfor all Python tests. - Use
pytest-mockorunittest.mockfor mocking. - Use fixtures for setup/teardown.
- Test both happy paths and edge cases.
- Mock external services and database connections.
- Use parameterized tests for edge cases.
- Document each test with a brief description.
Test TODO
Application Flow & Setup Tests
Setup Page Tests
- Test setup page is displayed when configuration is missing
- Test setup page form submission creates valid configuration
- Test setup page redirects to auth page after successful setup
- Test setup page validation for required fields
- Test setup page handles database connection errors gracefully
- Test setup completion flag is properly set in configuration
Authentication Flow Tests
- Test auth page is displayed when authentication token is invalid
- Test auth page is displayed when authentication token is missing
- Test successful login creates valid authentication token
- Test failed login shows appropriate error messages
- Test auth page redirects to main application after successful authentication
- Test token validation middleware correctly identifies valid/invalid tokens
- Test token refresh functionality
- Test session expiration handling
Main Application Access Tests
- Test index.html is served when authentication is valid
- Test unauthenticated users are redirected to auth page
- Test users without completed setup are redirected to setup page
- Test middleware enforces correct flow priority (setup → auth → main)
- Test authenticated user session persistence
- Test graceful handling of token expiration during active session
Integration Flow Tests
- Test complete user journey: setup → auth → main application
- Test application behavior when setup is completed but user is not authenticated
- Test application behavior when configuration exists but is corrupted
- Test concurrent user sessions and authentication state management
- Test application restart preserves setup and authentication state appropriately
Instruction to AI Agent:
Generate and check off each test case above as you complete it. Save all test files under src/tests/ using the specified structure and conventions.