Commit Graph
66 Commits
Author SHA1 Message Date
john-okeefe f15bf213ee fix(tests): Fix all remaining test compilation errors 2026-02-10 13:06:12 -05:00
john-okeefe 5b32b59781 fix(tests): Fix edge cases in test file migration 2026-02-10 13:03:32 -05:00
john-okeefe 6c610465eb refactor(tests): Update all test files to use TestServerSetup pattern 2026-02-10 13:01:12 -05:00
john-okeefe f3141f18ef refactor(tests): Create TestServerSetup struct with proper resource cleanup
BREAKING CHANGE: setupTestServer() now returns *TestServerSetup instead of (*httptest.Server, *database.Queries, *config.Config)

This fixes the database connection and goroutine leak issues where:
- Each test created a new pgxpool (default max_conns = 4)
- connManager.StartCleanupTask() goroutine was never stopped
- queueProcessor.Start() goroutine was never stopped
- ~160 tests = potential 640+ leaked connections

New TestServerSetup struct provides:
- Automatic cleanup via t.Cleanup()
- Proper goroutine cancellation
- Database pool closing
- Thread-safe close() method with mutex

Phase 1 of test cleanup refactor.
2026-02-10 12:58:51 -05:00
john-okeefe 57cb58bcbf test(kobo): Fix Kobo integration tests with proper device authentication
- Fix TestKoboInitialization: use setupDeviceTest() for device creation
- Fix TestKoboLibrarySync: remove /test-token/ route path, add device auth
- Fix TestKoboMarkupSync: add device auth and last-read-place test case
- Fix TestKoboBookmarkSync: add device auth and last-read-place test case
- Fix TestKoboAnalyticsGettests: add device authentication
- Add debug logging to all test functions
- Remove unused imports (config, database, middleware, router, services, sync)

Phase 3 of KOBO_IMPLEMENTATION_PLAN.md completed (Steps 7-12).

All tests now use proper device authentication (Bearer tokens + x-kobo-device headers)
and include test cases for the new last-read-place bookmark feature.
2026-02-10 12:41:09 -05:00
john-okeefe 2200720537 fix(middleware): Correct rate limit header type conversion 2026-02-10 12:06:12 -05:00
john-okeefe 2b24dd9dd3 fix: Fix failing integration tests and update documentation
- Fix TestUpdateDevice: Use correct JSON field name and handle float64 type
- Fix TestRejectDeviceRegistration: Expect message response instead of boolean
- Update approve device docs: Add missing response fields
- Update reject device docs: Correct message text and format
- Update Bruno API: Fix example response for reject endpoint

Both integration tests now pass while maintaining API consistency.
2026-02-10 10:22:19 -05:00
john-okeefe 1413c75b26 fix: Fix device response fields and add missing approved confirmation
feat: Improve device test infrastructure with setupDeviceTest helper

refactor: Standardize pending registrations API response field names
2026-02-10 09:31:35 -05:00
john-okeefe fefb1bd33b test: update tests for system settings and user list enhancements
System Settings Tests (new file):
- Create system_settings_test.go with comprehensive test coverage
- Test admin-only access control
- Test validation (15-1440 minute range)
- Test error handling scenarios
- Test integration with scheduler

User Tests Cleanup:
- Remove old TestScanSettings from user_test.go
- Scan settings moved to system-wide (no longer per-user)

Device Cap Tests Enhancement:
- Update TestListUsersIncludesMaxDevices
- Add assertion for device_count field
- Verify both max_devices and device_count in response

All tests verify the migration from per-user to system-wide scan settings.
2026-02-09 20:11:14 -05:00
john-okeefe 255b1c6cf5 Use /app/uploads directly for test library folder
- API validates folder exists before adding to library
- /app/uploads is mounted volume in container
- Avoids need to create subdirectories
- Simplifies test setup
2026-02-09 14:42:30 -05:00
john-okeefe 94ed96e3ad Fix test helper to use valid container folder path
- Change folder path from /tmp/test-library to /app/uploads/test-library
- /app/uploads is mounted volume in docker-compose test container
- Matches TEST_UPLOAD_PATH environment variable
- Fixes library folder creation 400 error in integration tests

Related: Library folder validation changes
2026-02-09 14:40:20 -05:00
john-okeefe ad910230d8 Fix test helper to add library folders before media items
- Update createTestMediaItemID to add folder after creating library
- Ensures proper test data setup
- Tests now reflect real-world usage pattern
- Also fixed existing syntax error in mime_type line

Fixes: TestCollectionsBulkOperations and related test failures
Related: Handler validation commit
2026-02-09 14:29:04 -05:00
john-okeefe 001647cbbe Fix goroutine leaks in sync queue processor and connection manager
Critical fixes to prevent goroutine leaks during application shutdown:

1. Sync Queue Processor:
   - Changed StartCleanupTask() to return context.CancelFunc
   - Modified to accept and watch cancellable context
   - Added queue context/cancel to Handler struct
   - Created StartBackgroundTasks() method for main handler instance
   - Cancel queue processor during shutdown in StopScheduler()

2. Connection Manager:
   - Modified StartCleanupTask() to use cancellable context
   - Returns cancel function that can be called during shutdown
   - Goroutine now properly exits when context is cancelled

3. Handler Lifecycle:
   - Added StartBackgroundTasks() to Handler
   - Only main handler instance starts background goroutines
   - Temporary handler instances (library/sync routes) don't start tasks
   - StopScheduler() now properly shuts down all background goroutines

4. Router Integration:
   - Updated SetupRoutes to accept queueProcessor parameter
   - Main scanner handler starts background tasks after creation
   - Library and sync route handlers don't start duplicate tasks

Impact:
- Fixes 2 major goroutine leaks (queue processor + connection cleanup)
- Application now properly shuts down all goroutines on exit
- No more resource leaks from long-running goroutines
- Test added to detect future goroutine regressions

Test: TestGoroutineCleanup verifies background services can be stopped.
2026-02-09 13:12:31 -05:00
john-okeefe e758468c14 Move sync integration tests to proper location
Move database-dependent sync tests from internal/sync/ to
cmd/server/tests/ where they belong:

- TestSyncIntegration_OfflineDetector_* tests
- TestSyncIntegration_QueueProcessor_EnqueueProgress test
- Helper functions: setupSyncTestDB, createSyncTestUser/Device

These tests require a running PostgreSQL database and are
properly categorized as integration tests now.

Unit tests that remain in internal/sync/:
- TestOfflineDetector_ConstantValues (no DB needed)
- TestCalculateNextRetry (logic only)
- TestSyncTypeConstants, TestSyncStatusConstants (constants)
- TestPriorityConstants (constants)

All unit tests now pass with `make test` (no DB required).
2026-02-09 10:45:42 -05:00
john-okeefe 38acc46988 refactor(tests): update test helpers and all test file references
- Rename createTestEbookID to createTestMediaItemID in test_helpers.go
- Update test helper comments and variable names (ebookReq -> mediaItemReq, etc.)
- Update all test file references:
  - analytics_test.go
  - book_matching_test.go
  - collections_bulk_test.go
  - kobo_test.go
  - media_bulk_test.go
  - opds_test.go
- Rename ebookID variable to mediaItemID in kobo_test.go
- Update test data to use 'Test Media Item' instead of 'Test Ebook'
2026-02-08 14:32:37 -05:00
john-okeefe 98f2913eb5 refactor(tests): remove getJSONInt helper, use float64 for JSON numeric values
Remove the getJSONInt helper function and update all test assertions to
expect float64 instead of int for JSON numeric fields, as Go's JSON
decoder unmarshals all numbers to float64 by default.

This simplifies the codebase by removing an unnecessary conversion
helper and makes tests more accurate to the actual JSON format.

Changes:
- Remove getJSONInt function from book_matching_test.go
- Update 5 assertions in book_matching_test.go to use float64
- Update 2 assertions in collections_bulk_test.go to use float64
- Update 2 assertions in media_bulk_test.go to use float64
- Add nil checks for optional numeric fields to prevent panics

Affected tests:
- TestBookMatchingBulkLink
- TestBookMatchingAutoLink
- TestCollectionsBulkOperations
- TestMediaBulkOperations

Note: Some test failures remain (API returning 400 instead of 200) but
these are legitimate test issues unrelated to type assertions.
2026-02-07 21:55:48 -05:00
john-okeefe c016a4582b fix(tests): initialize missing handlers in test setup
Fix nil pointer panics in integration tests by initializing the
four refactored handlers (MediaHandler, SearchHandler, MatchingHandler,
CollectionHandler) that were added during Phase 6 refactoring but
never added to the test setup.

These handlers were properly instantiated in cmd/server/main.go
(commit 9fd8a39) but were missing from cmd/server/tests/test_helpers.go,
causing panics when tests tried to use /api/collections and /api/media-items
endpoints.

Changes:
- Create worker with 3 concurrent workers
- Initialize CollectionHandler with queries and connManager
- Initialize MediaHandler with queries and worker
- Initialize SearchHandler with queries
- Initialize MatchingHandler with queries and connManager
- Add all four handlers to router.Config struct

Fixes panic errors:
- internal/handlers/collections.go:78 (CreateCollection nil pointer)
- internal/handlers/media.go:891 (CreateMediaItem nil pointer)

Tests now pass:
- TestCollectionsBulkOperations: PASS
- TestAnalytics*: PASS (all analytics tests)

Note: Bruno API tests and frontend were NOT affected as they use the
real running application (which has complete handler setup).
2026-02-07 21:48:07 -05:00
john-okeefe 8319ea2041 test: use dynamic path helper for upload folder test
- Replace hardcoded /app/uploads with getUploadPath()
- Update assertions to use dynamic paths
- Improve test log message to show actual path used
- Ensures tests work in both container and host environments
2026-02-07 21:30:22 -05:00
john-okeefe 737f01a17d feat: add dynamic path detection for container and host test environments
- Add isRunningInContainer() to detect test runtime environment
- Add getUploadPath() to resolve upload paths (container vs host)
- Add getCachePath() to resolve cache paths appropriately
- Update setupTestServer() to use dynamic path helpers
- Support environment variable overrides for flexibility
- Add os import for file system checks
2026-02-07 21:30:06 -05:00
john-okeefe 63f9763bcb test: remove CollectionHandler from test helpers
Remove the CollectionHandler field from router.Config struct literal
in cmd/server/tests/test_helpers.go. This field was removed from
the Config struct in a previous commit.

The collection routes are registered directly in handlers.SetupRoutes()
and don't need to be passed through the router config.
2026-02-07 18:02:56 -05:00
john-okeefe 4bdd08602c test: rename test files to better reflect their purpose
- Rename phase1_integration_test.go to universal_progress_integration_test.go
  (tests universal reading progress feature)
- Rename ebook_scanner_phase2_test.go to ebook_scanner_hash_test.go
  (tests hash calculation and file identification utilities)

These renames make the test suite more maintainable and self-documenting.
2026-02-07 17:06:45 -05:00
john-okeefe 73678a1df0 chore(tests): remove temporary test analysis file
- Remove cmd/server/tests/ANYSIS.md (temporary investigation file)
- No longer needed after test fixes completed
2026-02-06 22:00:12 -05:00
john-okeefe 786e809631 fix(tests): resolve type assertion and request body issues in tests
- Fix float64 type assertions for JSON numbers in conflicts bulk operations
- Create fresh HTTP request body for duplicate book tests
- Add nil checks for type assertions in device cap tests
- Properly extract user_id from JWT for existing users
- Trim trailing whitespace from response bodies
- All 3 previously failing tests now passing

Test results: 19/22 passing (86.4%)
Fixes: TestCollectionsBulkOperations, TestConflictsBulkDismiss, TestUpdateUserMaxDevices
2026-02-06 21:59:04 -05:00
john-okeefe 327be1af63 test: update websocket test signatures
- Remove handler parameter from test function calls
- Update test signatures to match new setupTestServer return values
- Fix compilation errors after test helper refactoring
- Maintain websocket test functionality
2026-02-06 17:07:52 -05:00
john-okeefe 7381d9178b test: update opds, queue, and refresh token test signatures
- Remove handler parameter from test function calls
- Update test signatures to match new setupTestServer return values
- Fix compilation errors after test helper refactoring
- Ensure test consistency for opds, queue, and auth endpoints
2026-02-06 17:07:27 -05:00
john-okeefe 0781cd871e test: update kobo and media test signatures
- Remove handler parameter from test function calls
- Update test signatures to match new setupTestServer return values
- Fix compilation errors after test helper refactoring
- Maintain test functionality for kobo and media endpoints
2026-02-06 17:07:12 -05:00
john-okeefe 2ff8506718 test: update conflicts and device test signatures
- Remove handler parameter from test function calls
- Update test signatures to match new setupTestServer return values
- Fix compilation errors after test helper refactoring
- Ensure test consistency across all test files
2026-02-06 17:06:12 -05:00
john-okeefe 56efae971e test: update test signatures to match new test_helpers.go
- Remove handler parameter from test function calls
- Update test signatures to use new return values from setupTestServer
- Fix compilation errors after test helper refactoring
- Maintain test functionality while simplifying setup
2026-02-06 17:05:16 -05:00
john-okeefe aee7fb4960 fix: use config.LoadConfig() in test helpers for consistency
- Replace manual config construction with config.LoadConfig()
- Remove problematic password validation logic
- Apply test-specific overrides after loading config
- Clean up unused imports (os, strings)
- Tests now use same configuration method as main application
- Fixes database authentication issues in integration tests
2026-02-06 17:03:56 -05:00
john-okeefe 17e0fc2625 test: fix test login password to match bcrypt hash
Fixed loginTestUser to use 'Test@Pass123!' (with @ symbol) to match the
bcrypt hash that was generated using Go's golang.org/x/crypto/bcrypt library.
2026-02-06 13:55:28 -05:00
john-okeefe 034e261c78 test: fix test password hash to use Go-generated bcrypt
Changed login test password from 'Test@Pass123!' to 'testpass123' and updated
bcrypt hash to use Go's golang.org/x/crypto/bcrypt library instead of Python's bcrypt.
2026-02-06 13:52:12 -05:00
john-okeefe 014047a1e3 test: update test helpers to use router package
Changes to test_helpers.go:
- Import router package and use router.RegisterRoutes()
- Create all necessary handlers (auth, device, koreader, ws, conflict, analytics, queue, opds)
- Add proper validator setup
- Add CustomValidator type
- Remove unused pgtype import

This makes integration tests use the same router configuration as production,
ensuring tests cover the actual API behavior and route structure.
2026-02-06 13:37:23 -05:00
john-okeefe 655ed9225f Update code references and tests: Bookmann → Bookhoard
Code changes:
- main.go: Update cache directory path
- sidecar.go: Update file extension (.bookmann.json → .bookhoard.json)
- security.go: Update CORS example URLs
- queue_test.go: Update test database name
- feed_test.go: Update test assertions
- phase1_integration_test.go: Update test email addresses
- TEST_COVERAGE.md: Update project references

Part of project rename to Bookhoard.
2026-02-01 16:21:10 -05:00
john-okeefe 4e1feca124 Rename test file references: Bookmann → Bookhoard
Test file updates:
- Update import paths in test files: bookmann/internal → bookhoard/internal
- Update test helper functions and references
- Update test comments and documentation

This is part 6 of the project rename to Bookhoard.
2026-02-01 16:12:18 -05:00
john-okeefe dacbea6f85 test: add comprehensive media-item ISBN validation tests
New test file with 5 test suites:
- TestMediaItemISBNNormalization (8 test cases)
- TestMediaItemISBNEdgeCases (3 test cases)
- TestMediaItemsPagination (5 test cases)
- TestMediaItemLibraryRequirement (2 test cases)
- TestUpdateMediaItemISBN (1 test case)

Features:
- Tests use /api/media-items endpoint (not deprecated /api/ebooks)
- Real API calls (not mock handlers)
- Comprehensive ISBN-10/ISBN-13 normalization coverage
- Pagination validation with limit/offset edge cases
- Library requirement validation

This replaces the functionality lost from isbn_and_library_test.go
with modern, working tests using current API endpoints.

Phase 3: Test Suite Cleanup - Replacement Tests
2026-02-01 14:11:24 -05:00
john-okeefe 01321d1720 test: remove outdated ISBN normalization tests
- Deleted isbn_and_library_test.go (507 lines)
- All tests used deprecated /api/ebooks endpoint
- Tests were mock-based, not real API calls
- Functionality will be replaced with modern tests

This is part of legacy code cleanup Phase 3.
Phase 3: Test Suite Cleanup
2026-02-01 14:11:18 -05:00
john-okeefe 72db266e23 test: remove outdated ebook pagination tests
- Removed TestPaginationAndFiltering function
- Deleted 4 test cases using deprecated /api/ebooks endpoint
- Tests for pagination already exist in library_test.go using /api/media-items

This is part of legacy code cleanup Phase 3.
Phase 3: Test Suite Cleanup
2026-02-01 14:11:17 -05:00
john-okeefe 351c68b0b8 test: add comprehensive test coverage for API endpoints and services 2026-02-01 13:21:34 -05:00
john-okeefe 9b1282cd08 test: remove hardcoded refresh token test from main_test.go 2026-02-01 13:21:32 -05:00
john-okeefe 5a7144b98e feat: add device management and queue management routes
- Add /devices route for device management interface
- Add /conflicts route for sync conflict resolution
- Add /queue route for sync queue management
- Add comprehensive tests for device cap management
- Add test suite for queue management
2026-01-31 18:25:28 -05:00
john-okeefe 8d55b7c5b5 Add comprehensive test suite for device cap management
- Test successful updates (5, 10, 50, 100 devices)
- Test validation failures (0, -1, 101, 1000 devices)
- Test authentication requirements (no token, non-admin)
- Test non-existent user ID
- Test missing user ID in URL
- Test max_devices field in user list response
- Add 20+ test cases across 7 test functions
- Helper functions for admin user creation and login
2026-01-31 13:06:42 -05:00
john-okeefe 5bb273f6aa Improve Phase 1 integration test robustness
Update test credentials and add better error handling for user registration and login scenarios to prevent test failures from incomplete test runs.
2026-01-31 11:45:56 -05:00
john-okeefe 2d2d643873 Add sync conflict detection and resolution system
Implement conflict detection for concurrent reading progress updates from different devices. Adds conflict management endpoints for listing, viewing, and resolving conflicts.

- Add ConflictHandler with CRUD endpoints for conflict management
- Implement automatic conflict detection in KOReader progress updates
- Add WebSocket broadcast for real-time conflict notifications
- Add database query for listing user conflicts by status
- Add integration tests and Bruno API test collection
2026-01-31 11:45:52 -05:00
john-okeefe 9b41b3ecb0 Add refresh token flow integration test
- Test login returns both access_token and refresh_token
- Test refresh endpoint accepts UUID token and returns new access_token
- Verifies end-to-end refresh token flow works correctly
2026-01-31 11:44:47 -05:00
john-okeefe a3aa9f67ac feat: add Kobo device sync support and fix device route protection
- Add Kobo sync handler with markup, bookmark, analytics, and initialization endpoints
- Add Kobo integration tests and Bruno API test collection
- Move device approve/reject routes from public to protected routes
- Enhance test infrastructure with DATABASE_URL support and helper functions
- Fix device GetDevice handler nil pointer handling
- Clean up test reports and session files
2026-01-30 23:58:34 -05:00
john-okeefe 77d683277a test: add WebSocket integration tests
Add comprehensive WebSocket test coverage:
- TestWebSocketConnection: Basic connection and JWT auth
- TestWebSocketDeviceAuth: Device token authentication
- TestWebSocketProgressBroadcast: Real-time update delivery
- TestWebSocketPingPong: Heartbeat mechanism
- TestWebSocketConnectionLimit: Multiple concurrent connections
- TestWebSocketInvalidToken: Rejection of invalid tokens
- Helper function for test media item creation

Update test helpers to create ConnectionManager for tests.
Tests verify WebSocket connection, authentication, and
real-time progress broadcast functionality.
2026-01-30 21:48:30 -05:00
john-okeefe f8a6c3d227 Phase 3 Week 7: Add KOReader routes, tests, and documentation
- Add KOReader sync endpoints to main application router
- Create Bruno API collection for testing KOReader endpoints
- Add integration tests for KOReader functionality
- Include comprehensive README with setup instructions
- Test coverage for progress, metadata, library, and bookmarks sync
- Part of Phase 3 KOReader Integration implementation
2026-01-30 20:55:20 -05:00
john-okeefe 95fe849eeb Fix test infrastructure and device UUID handling
- Remove manual device ID generation, use database-generated IDs
- Add comprehensive test helpers (setupTestServer, loginTestUser, getTestUserID)
- Add cleanup step for existing test users in integration tests
- Fix UUID parsing from database responses
2026-01-30 20:16:19 -05:00
john-okeefe 9d32e5a0f0 Add comprehensive integration tests for Phase 2 device management
Test Files Added:
- integration_test.sh: Automated integration test script
  * Tests full user flow: register, login, library creation, scanning
  * Tests device registration and management
  * Color-coded output with pass/fail tracking
  * Generates detailed test results report

- cmd/server/tests/device_test.go: Unit tests for device endpoints
  * TestDeviceRegistrationFlow: Full registration flow test
  * TestListDevices: Device listing functionality
  * TestUpdateDevice: Device settings updates
  * TestDeleteDevice: Device removal
  * TestDeviceAuthentication: Device auth middleware test

- cmd/server/tests/phase1_integration_test.go: Phase 1 integration tests
  * Tests universal progress tracking
  * Tests format group detection
  * Tests progress conversion

Test Coverage:
- Device registration with web-based approval flow
- Device management (list, update, delete)
- Device authentication and token validation
- User authentication and authorization
- Library creation and management
- Scanner integration
- Media items listing

Notes:
- Tests designed to run against live server on localhost:8765
- Integration test script uses bash/curl for endpoint testing
- Device tests require helper functions to be implemented
2026-01-30 16:57:01 -05:00
john-okeefe 07abcabaa8 refactor: clean up tests and templates for media-items system
- Remove ebook-specific test files (ebook_test.go, integration_test.go, notes_highlights_test.go)
- Update search_test.go for media-items API paths
- Regenerate templates (bookshelf_templ.go, header_templ.go)
- Add ISBN normalization utility function
- Clean up test suite to focus on media-items functionality

Aligns tests and templates with unified media-items architecture
2026-01-30 13:52:11 -05:00