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'
This commit is contained in:
2026-02-08 14:32:37 -05:00
parent a9e0b33002
commit 38acc46988
7 changed files with 45 additions and 45 deletions
+1 -1
View File
@@ -331,7 +331,7 @@ func TestAnalyticsPopularBooks(t *testing.T) {
token := loginTestUser(t, ts, db)
// First create a book and some reading history
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
// Create reading history for the book
historyReq := map[string]interface{}{
+2 -2
View File
@@ -38,7 +38,7 @@ func TestBookMatchingQueryBooks(t *testing.T) {
defer ts.Close()
token := loginTestUser(t, ts, db)
_ = createTestEbookID(t, ts, token)
_ = createTestMediaItemID(t, ts, token)
req := map[string]interface{}{
"title": "Test Ebook",
@@ -180,7 +180,7 @@ func TestBookMatchingBulkLink(t *testing.T) {
defer ts.Close()
token := loginTestUser(t, ts, db)
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
req := map[string]interface{}{
"links": []map[string]interface{}{
+8 -8
View File
@@ -66,7 +66,7 @@ func TestCollectionsBulkOperations(t *testing.T) {
defer ts.Close()
token := loginTestUser(t, ts, db)
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
req := map[string]interface{}{
"operations": []map[string]interface{}{
@@ -186,7 +186,7 @@ func TestCollectionsBulkOperations(t *testing.T) {
collectionID := collectionResult["id"].(string)
// Create a book
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
// Add book to collection
addReq := map[string]interface{}{
@@ -249,9 +249,9 @@ func TestCollectionsBulkOperations(t *testing.T) {
collectionID := collectionResult["id"].(string)
// Create multiple books
bookID1 := createTestEbookID(t, ts, token)
bookID2 := createTestEbookID(t, ts, token)
bookID3 := createTestEbookID(t, ts, token)
bookID1 := createTestMediaItemID(t, ts, token)
bookID2 := createTestMediaItemID(t, ts, token)
bookID3 := createTestMediaItemID(t, ts, token)
// Add all books to collection
addReq := map[string]interface{}{
@@ -326,8 +326,8 @@ func TestCollectionsBulkOperations(t *testing.T) {
collectionID2 := collectionResult2["id"].(string)
// Create books
bookID1 := createTestEbookID(t, ts, token)
bookID2 := createTestEbookID(t, ts, token)
bookID1 := createTestMediaItemID(t, ts, token)
bookID2 := createTestMediaItemID(t, ts, token)
// Add books to multiple collections
addReq := map[string]interface{}{
@@ -388,7 +388,7 @@ func TestCollectionsBulkOperations(t *testing.T) {
collectionID := collectionResult["id"].(string)
// Create a book
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
// Add book to collection
addReq := map[string]interface{}{
+10 -10
View File
@@ -22,7 +22,7 @@ func TestKoboInitialization(t *testing.T) {
token := loginTestUser(t, ts, db)
_ = getTestUserID(t, db)
_ = createTestEbookID(t, ts, token)
_ = createTestMediaItemID(t, ts, token)
t.Run("successful initialization", func(t *testing.T) {
req, _ := http.NewRequest("GET", ts.URL+"/api/sync/kobo/test-token/v1/initialization", nil)
@@ -46,7 +46,7 @@ func TestKoboLibrarySync(t *testing.T) {
defer closeTestServer(t, ts, db)
token := loginTestUser(t, ts, db)
_ = createTestEbookID(t, ts, token)
_ = createTestMediaItemID(t, ts, token)
t.Run("successful library sync", func(t *testing.T) {
req, _ := http.NewRequest("GET", ts.URL+"/api/sync/kobo/test-token/v1/initialization", nil)
@@ -70,13 +70,13 @@ func TestKoboMarkupSync(t *testing.T) {
defer closeTestServer(t, ts, db)
token := loginTestUser(t, ts, db)
ebookID := createTestEbookID(t, ts, token)
mediaItemID := createTestMediaItemID(t, ts, token)
t.Run("successful markup sync with annotations and bookmarks", func(t *testing.T) {
reqBody := map[string]interface{}{
"ReadingSync": []map[string]interface{}{
{
"ContentId": ebookID,
"ContentId": mediaItemID,
"PercentRead": 45.6,
"EntitlementId": "ent-123",
"RemainingTimeMinutes": 120,
@@ -86,14 +86,14 @@ func TestKoboMarkupSync(t *testing.T) {
"BookmarkSync": []map[string]interface{}{
{
"BookmarkId": "bookmark-1",
"ContentId": ebookID,
"ContentId": mediaItemID,
"BookmarkText": "This is highlighted text",
"BookmarkType": "annotation",
"BookmarkTitle": "Chapter 3",
},
{
"BookmarkId": "bookmark-2",
"ContentId": ebookID,
"ContentId": mediaItemID,
"BookmarkText": "This is my note abouts book",
"BookmarkType": "bookmark",
},
@@ -126,14 +126,14 @@ func TestKoboBookmarkSync(t *testing.T) {
defer closeTestServer(t, ts, db)
token := loginTestUser(t, ts, db)
ebookID := createTestEbookID(t, ts, token)
mediaItemID := createTestMediaItemID(t, ts, token)
t.Run("successful bookmark sync", func(t *testing.T) {
reqBody := map[string]interface{}{
"BookmarkSync": []map[string]interface{}{
{
"BookmarkId": "bookmark-3",
"ContentId": ebookID,
"ContentId": mediaItemID,
"BookmarkText": "Important note abouts book",
"BookmarkType": "bookmark",
"DateCreated": "2026-01-30T19:55:00Z",
@@ -167,14 +167,14 @@ func TestKoboAnalyticsGettests(t *testing.T) {
defer closeTestServer(t, ts, db)
token := loginTestUser(t, ts, db)
ebookID := createTestEbookID(t, ts, token)
mediaItemID := createTestMediaItemID(t, ts, token)
t.Run("successful analytics tests", func(t *testing.T) {
reqBody := map[string]interface{}{
"meta": map[string]string{
"name": "Kobo Analytics Tests",
},
"ContentId": ebookID,
"ContentId": mediaItemID,
"ReadingEvent": "Reading",
"RemainingTimeMin": 180,
"PercentRead": 67.8,
+6 -6
View File
@@ -94,8 +94,8 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, ts, db)
// Create test books
bookID1 := createTestEbookID(t, ts, token)
bookID2 := createTestEbookID(t, ts, token)
bookID1 := createTestMediaItemID(t, ts, token)
bookID2 := createTestMediaItemID(t, ts, token)
bookID3 := uuid.New().String()
req := map[string]interface{}{
@@ -234,8 +234,8 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, ts, db)
// Create test books
bookID1 := createTestEbookID(t, ts, token)
bookID2 := createTestEbookID(t, ts, token)
bookID1 := createTestMediaItemID(t, ts, token)
bookID2 := createTestMediaItemID(t, ts, token)
req := map[string]interface{}{
"book_ids": []string{bookID1, bookID2},
@@ -274,7 +274,7 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, ts, db)
// Create test books
bookID1 := createTestEbookID(t, ts, token)
bookID1 := createTestMediaItemID(t, ts, token)
req := map[string]interface{}{
"book_ids": []string{bookID1},
@@ -308,7 +308,7 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, ts, db)
// Create test books
bookID1 := createTestEbookID(t, ts, token)
bookID1 := createTestMediaItemID(t, ts, token)
req := map[string]interface{}{
"book_ids": []string{bookID1},
+6 -6
View File
@@ -166,7 +166,7 @@ func TestOPDSEndpoints(t *testing.T) {
token := loginTestUser(t, ts, db)
deviceID := uuid.New()
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
httpReq, _ := http.NewRequest("GET", ts.URL+"/opds/devices/"+deviceID.String()+"/download/"+bookID, nil)
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -217,7 +217,7 @@ func TestOPDSEndpoints(t *testing.T) {
token := loginTestUser(t, ts, db)
deviceID := uuid.New()
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
httpReq, _ := http.NewRequest("GET", ts.URL+"/opds/devices/"+deviceID.String()+"/cover/"+bookID, nil)
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -252,7 +252,7 @@ func TestOPDSEndpoints(t *testing.T) {
token := loginTestUser(t, ts, db)
deviceID := uuid.New()
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
httpReq, _ := http.NewRequest("GET", ts.URL+"/opds/devices/"+deviceID.String()+"/formats/"+bookID, nil)
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -275,7 +275,7 @@ func TestOPDSConversion(t *testing.T) {
token := loginTestUser(t, ts, db)
deviceID := uuid.New()
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
// Request KEPUB format
httpReq, _ := http.NewRequest("GET", ts.URL+"/opds/devices/"+deviceID.String()+"/download/"+bookID+"?format=kepub", nil)
@@ -297,7 +297,7 @@ func TestOPDSConversion(t *testing.T) {
token := loginTestUser(t, ts, db)
deviceID := uuid.New()
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
// Request default format (no format parameter)
httpReq, _ := http.NewRequest("GET", ts.URL+"/opds/devices/"+deviceID.String()+"/download/"+bookID, nil)
@@ -318,7 +318,7 @@ func TestOPDSConversion(t *testing.T) {
token := loginTestUser(t, ts, db)
deviceID := uuid.New()
bookID := createTestEbookID(t, ts, token)
bookID := createTestMediaItemID(t, ts, token)
// Request unsupported format
httpReq, _ := http.NewRequest("GET", ts.URL+"/opds/devices/"+deviceID.String()+"/download/"+bookID+"?format=pdf", nil)
+12 -12
View File
@@ -269,12 +269,12 @@ func getTestUserID(t *testing.T, db *database.Queries) uuid.UUID {
return userUUID
}
// createTestEbookID creates a test ebook and returns its ID
func createTestEbookID(t *testing.T, ts *httptest.Server, token string) string {
// createTestMediaItemID creates a test media item and returns its ID
func createTestMediaItemID(t *testing.T, ts *httptest.Server, token string) string {
// First create a library
libReq := map[string]interface{}{
"name": "Test Library",
"description": "A test library for ebooks",
"description": "A test library for media items",
"type": "ebooks",
}
libBody, _ := json.Marshal(libReq)
@@ -295,18 +295,18 @@ func createTestEbookID(t *testing.T, ts *httptest.Server, token string) string {
libData := libResult["id"].(string)
// Create a test ebook
ebookReq := map[string]interface{}{
// Create a test media item
mediaItemReq := map[string]interface{}{
"library_id": libData,
"title": "Test Ebook",
"title": "Test Media Item",
"author": "Test Author",
"file_path": "/tmp/test.epub",
"file_size": 1024,
"mime_type": "application/epub+zip",
}
ebookBody, _ := json.Marshal(ebookReq)
mediaItemBody, _ := json.Marshal(mediaItemReq)
req2, _ := http.NewRequest("POST", ts.URL+"/api/media-items", bytes.NewBuffer(ebookBody))
req2, _ := http.NewRequest("POST", ts.URL+"/api/media-items", bytes.NewBuffer(mediaItemBody))
req2.Header.Set("Content-Type", "application/json")
req2.Header.Set("Authorization", "Bearer "+token)
@@ -316,9 +316,9 @@ func createTestEbookID(t *testing.T, ts *httptest.Server, token string) string {
require.Equal(t, http.StatusCreated, resp2.StatusCode)
var ebookResult map[string]interface{}
json.NewDecoder(resp2.Body).Decode(&ebookResult)
var mediaItemResult map[string]interface{}
json.NewDecoder(resp2.Body).Decode(&mediaItemResult)
ebookID := ebookResult["id"].(string)
return ebookID
mediaItemID := mediaItemResult["id"].(string)
return mediaItemID
}