refactor(tests): Update all test files to use TestServerSetup pattern
This commit is contained in:
@@ -14,15 +14,14 @@ import (
|
||||
// TestMediaBulkOperations tests bulk media operations
|
||||
func TestMediaBulkOperations(t *testing.T) {
|
||||
t.Run("BulkDeleteBooks_WithoutAuth", func(t *testing.T) {
|
||||
ts, _, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{uuid.New().String()},
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
@@ -34,17 +33,16 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkDeleteBooks_EmptyBookIDs", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{},
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -57,17 +55,16 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkDeleteBooks_InvalidBookIDs", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{"invalid-uuid", "another-invalid"},
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -88,14 +85,13 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkDeleteBooks_WithValidBooks", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
// Create test books
|
||||
bookID1 := createTestMediaItemID(t, ts, token)
|
||||
bookID2 := createTestMediaItemID(t, ts, token)
|
||||
bookID1 := createTestMediaItemID(t, setup.Server, token)
|
||||
bookID2 := createTestMediaItemID(t, setup.Server, token)
|
||||
bookID3 := uuid.New().String()
|
||||
|
||||
req := map[string]interface{}{
|
||||
@@ -103,7 +99,7 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -126,13 +122,12 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkDeleteBooks_InvalidRequestBody", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
// Send invalid JSON
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-delete", bytes.NewBuffer([]byte("invalid json")))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer([]byte("invalid json")))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -145,8 +140,7 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkUpdateBooks_WithoutAuth", func(t *testing.T) {
|
||||
ts, _, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{uuid.New().String()},
|
||||
@@ -156,7 +150,7 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
@@ -168,10 +162,9 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkUpdateBooks_EmptyBookIDs", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{},
|
||||
@@ -181,7 +174,7 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -194,10 +187,9 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkUpdateBooks_InvalidBookIDs", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{"invalid-uuid"},
|
||||
@@ -207,7 +199,7 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -228,14 +220,13 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkUpdateBooks_UpdateTags", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
// Create test books
|
||||
bookID1 := createTestMediaItemID(t, ts, token)
|
||||
bookID2 := createTestMediaItemID(t, ts, token)
|
||||
bookID1 := createTestMediaItemID(t, setup.Server, token)
|
||||
bookID2 := createTestMediaItemID(t, setup.Server, token)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{bookID1, bookID2},
|
||||
@@ -245,7 +236,7 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -268,13 +259,12 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkUpdateBooks_UpdateReadingStatus", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
// Create test books
|
||||
bookID1 := createTestMediaItemID(t, ts, token)
|
||||
bookID1 := createTestMediaItemID(t, setup.Server, token)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{bookID1},
|
||||
@@ -284,7 +274,7 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -302,13 +292,12 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkUpdateBooks_UpdateMultipleFields", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
// Create test books
|
||||
bookID1 := createTestMediaItemID(t, ts, token)
|
||||
bookID1 := createTestMediaItemID(t, setup.Server, token)
|
||||
|
||||
req := map[string]interface{}{
|
||||
"book_ids": []string{bookID1},
|
||||
@@ -320,7 +309,7 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
@@ -338,13 +327,12 @@ func TestMediaBulkOperations(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BulkUpdateBooks_InvalidRequestBody", func(t *testing.T) {
|
||||
ts, db, _ := setupTestServer(t)
|
||||
defer ts.Close()
|
||||
setup := setupTestServer(t)
|
||||
|
||||
token := loginTestUser(t, ts, db)
|
||||
token := loginTestUser(t, setup.Server, setup.DB)
|
||||
|
||||
// Send invalid JSON
|
||||
httpReq, _ := http.NewRequest("POST", ts.URL+"/api/books/bulk-update", bytes.NewBuffer([]byte("invalid json")))
|
||||
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer([]byte("invalid json")))
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user