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
This commit is contained in:
2026-02-14 00:12:28 -05:00
parent 962bab1df0
commit 8e054bd149
10 changed files with 168 additions and 185 deletions
+9 -11
View File
@@ -12,8 +12,7 @@ import (
// TestOPDSEndpoints tests OPDS (Open Publication Distribution System) endpoints
func TestOPDSEndpoints(t *testing.T) {
setup := setupTestServer(t)
token := loginTestUser(t, setup.Server, setup.DB)
_ = createTestMediaItemID(t, setup.Server, token)
_ = createTestMediaItemID(t, setup.Server)
client := &http.Client{}
t.Run("GetDeviceCatalog_WithoutDeviceAuth", func(t *testing.T) {
@@ -146,7 +145,7 @@ func TestOPDSEndpoints(t *testing.T) {
t.Run("DownloadBook_ValidIDs", func(t *testing.T) {
deviceSetup := setupDeviceTest(t)
device := deviceSetup.CreateDevice(t, "Test OPDS Device", "koreader", "opds-download-test")
bookID := createTestMediaItemID(t, setup.Server, token)
bookID := createTestMediaItemID(t, setup.Server)
httpReq, _ := http.NewRequest("GET", setup.Server.URL+"/opds/devices/"+device.ID.String()+"/download/"+bookID, nil)
httpReq.Header.Set("Authorization", "Bearer "+device.AuthToken)
@@ -183,7 +182,7 @@ func TestOPDSEndpoints(t *testing.T) {
t.Run("GetCoverImage_ValidIDs", func(t *testing.T) {
deviceSetup := setupDeviceTest(t)
device := deviceSetup.CreateDevice(t, "Test OPDS Device", "koreader", "opds-cover-test")
bookID := createTestMediaItemID(t, setup.Server, token)
bookID := createTestMediaItemID(t, setup.Server)
httpReq, _ := http.NewRequest("GET", setup.Server.URL+"/opds/devices/"+device.ID.String()+"/cover/"+bookID, nil)
httpReq.Header.Set("Authorization", "Bearer "+device.AuthToken)
@@ -210,7 +209,7 @@ func TestOPDSEndpoints(t *testing.T) {
t.Run("ListFormats_ValidDeviceID", func(t *testing.T) {
deviceSetup := setupDeviceTest(t)
device := deviceSetup.CreateDevice(t, "Test OPDS Device", "koreader", "opds-formats-test")
bookID := createTestMediaItemID(t, setup.Server, token)
bookID := createTestMediaItemID(t, setup.Server)
httpReq, _ := http.NewRequest("GET", setup.Server.URL+"/opds/devices/"+device.ID.String()+"/formats/"+bookID, nil)
httpReq.Header.Set("Authorization", "Bearer "+device.AuthToken)
@@ -227,13 +226,13 @@ func TestOPDSEndpoints(t *testing.T) {
// TestOPDSConversion tests on-the-fly conversion for downloads
func TestOPDSConversion(t *testing.T) {
setup := setupTestServer(t)
token := loginTestUser(t, setup.Server, setup.DB)
_ = createTestMediaItemID(t, setup.Server)
client := &http.Client{}
t.Run("DownloadKEPUB_FormatParameter", func(t *testing.T) {
deviceSetup := setupDeviceTest(t)
device := deviceSetup.CreateDevice(t, "Test OPDS Device", "kobo", "opds-kepub-test")
bookID := createTestMediaItemID(t, setup.Server, token)
bookID := createTestMediaItemID(t, setup.Server)
// Request KEPUB format
httpReq, _ := http.NewRequest("GET", setup.Server.URL+"/opds/devices/"+device.ID.String()+"/download/"+bookID+"?format=kepub", nil)
@@ -251,7 +250,7 @@ func TestOPDSConversion(t *testing.T) {
t.Run("DownloadEPUB_DefaultFormat", func(t *testing.T) {
deviceSetup := setupDeviceTest(t)
device := deviceSetup.CreateDevice(t, "Test OPDS Device", "koreader", "opds-epub-test")
bookID := createTestMediaItemID(t, setup.Server, token)
bookID := createTestMediaItemID(t, setup.Server)
// Request default format (no format parameter)
httpReq, _ := http.NewRequest("GET", setup.Server.URL+"/opds/devices/"+device.ID.String()+"/download/"+bookID, nil)
@@ -268,7 +267,7 @@ func TestOPDSConversion(t *testing.T) {
t.Run("Download_UnsupportedFormat", func(t *testing.T) {
deviceSetup := setupDeviceTest(t)
device := deviceSetup.CreateDevice(t, "Test OPDS Device", "koreader", "opds-unsupported-test")
bookID := createTestMediaItemID(t, setup.Server, token)
bookID := createTestMediaItemID(t, setup.Server)
// Request unsupported format
httpReq, _ := http.NewRequest("GET", setup.Server.URL+"/opds/devices/"+device.ID.String()+"/download/"+bookID+"?format=pdf", nil)
@@ -286,8 +285,7 @@ func TestOPDSConversion(t *testing.T) {
// TestOPDSEdgeCases tests edge cases for OPDS endpoints
func TestOPDSEdgeCases(t *testing.T) {
setup := setupTestServer(t)
token := loginTestUser(t, setup.Server, setup.DB)
_ = token // Used for creating media items in device setup
_ = createTestMediaItemID(t, setup.Server)
client := &http.Client{}
t.Run("Catalog_EmptyLibrary", func(t *testing.T) {