Commit Graph
12 Commits
Author SHA1 Message Date
john-okeefe a6700f73e0 fix(tests): handle all Close() and Decode() errors across integration tests
Replace all unhandled resp.Body.Close() calls throughout the test suite:

- Deferred calls: replace 'defer VAR.Body.Close()' with a closure that explicitly
  discards the error via 'defer func(Body io.ReadCloser) { _ = Body.Close() }(VAR.Body)'
- Immediate calls: replace 'VAR.Body.Close()' with '_ = VAR.Body.Close()'

Replace all unhandled json.NewDecoder(VAR.Body).Decode(&x) calls with error capture
and require.NoError assertion. Files using httptest.ResponseRecorder (collections_preview,
processing_issues) use 'err :=' declaration; suite-style tests (scanner_integration,
dashboard_integration) use s.T() instead of t.
2026-04-21 20:33:05 -04:00
john-okeefe f54508e4dd test: improve test isolation and setup management
Add Token and RegularToken fields to TestServerSetup for pre-authenticated
access. Update setupTestServer to create fresh users with valid tokens at
initialization time. Simplify createTestMediaItemID to use setup.Token.
Remove loginTestUser, loginRegularUser, loginAdminUser functions in favor
of setup.Token/setup.RegularToken. Update createTestUserOnce and
getTestUserID/getRegularUserID to be idempotent. Update all test files to
use setup.Token instead of calling login helpers.
2026-02-22 01:57:22 -05:00
john-okeefe 8e054bd149 fix: update test files for token handling and response parsing
- Update callers of createTestMediaItemID to not pass token
- Fix loginAdminUser to delete/recreate admin user for consistent state
- Fix TestListAllQueueItems_Admin to parse response as map with 'items' key
- Remove unused token variables from tests
- Update device_test.go with admin password hash constant
2026-02-14 00:12:28 -05:00
john-okeefe 368c790c67 refactor(tests): enhance test infrastructure with library/collection helpers
- Add LibraryTestData struct to TestDeviceSetup
- Implement CreateLibrary() for proper library creation in tests
- Implement CreateCollection() for test collection support
- Improve test isolation with dedicated library creation

This provides a more robust foundation for integration tests that need
proper library management support.
2026-02-13 20:04:47 -05:00
john-okeefe 3f5535aa38 Phase 1: Convert bulk test operations to struct-based assertions
collections_bulk_test.go:
- Define local BulkAddOperation and BulkAddBooksRequest structs
- Convert 3 tests (WithoutAuth, EmptyOperations, InvalidCollectionID)
- Add database verification comments for future implementation
- Impact: Pattern for 200+ remaining bulk test conversions

media_bulk_test.go:
- Add database verification to bulk delete operations
- Add imports for database, handlers, context, pgtype
- Convert BulkDeleteBooks_WithoutAuth to verify DB state
- Impact: Ensures bulk deletes actually remove records

Total conversions: 5 tests from map-based to struct-based assertions
2026-02-13 17:42:37 -05:00
john-okeefe 891209b4bd test(infrastructure): Configure pgxpool with max_conns=1
Fix database connection exhaustion in tests by setting max_conns=1
when creating pgxpool via pgxpool.ParseConfig().

- Update setupTestServer() in test_helpers.go
- Update setupSyncTestDB() in sync_integration_test.go

This reduces per-test connection usage from 4 to 1, keeping total
connections well under PostgreSQL's default max_connections=100.

78 tests × 1 connection = 78 connections (down from 312 potential)

Fixes test failures: "FATAL: sorry, too many clients already"

See PROJECT_GUIDELINES.md Testing section for details.
2026-02-11 10:37:38 -05:00
john-okeefe bb4b85afcc test: update bulk operations tests for /api/media-items/ endpoints
- Update all test URLs from /api/books/ to /api/media-items/
- Update request structures: book_ids → media_item_ids
- Update bulk-update request format to array of operations
- Update response assertions: success → deleted/updated
- Update result assertions: book_id → media_item_id
2026-02-10 19:57:28 -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 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 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 351c68b0b8 test: add comprehensive test coverage for API endpoints and services 2026-02-01 13:21:34 -05:00