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