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
This commit is contained in:
2026-02-10 19:57:28 -05:00
parent 03225cf6e2
commit bb4b85afcc
+77 -47
View File
@@ -17,11 +17,11 @@ func TestMediaBulkOperations(t *testing.T) {
setup := setupTestServer(t)
req := map[string]interface{}{
"book_ids": []string{uuid.New().String()},
"media_item_ids": []string{uuid.New().String()},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-delete", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
client := &http.Client{}
@@ -38,11 +38,11 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
req := map[string]interface{}{
"book_ids": []string{},
"media_item_ids": []string{},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-delete", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -60,11 +60,11 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
req := map[string]interface{}{
"book_ids": []string{"invalid-uuid", "another-invalid"},
"media_item_ids": []string{"invalid-uuid", "another-invalid"},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-delete", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -89,17 +89,17 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
// Create test books
bookID1 := createTestMediaItemID(t, setup.Server, token)
bookID2 := createTestMediaItemID(t, setup.Server, token)
bookID3 := uuid.New().String()
// Create test media items
mediaID1 := createTestMediaItemID(t, setup.Server, token)
mediaID2 := createTestMediaItemID(t, setup.Server, token)
mediaID3 := uuid.New().String()
req := map[string]interface{}{
"book_ids": []string{bookID1, bookID2, bookID3},
"media_item_ids": []string{mediaID1, mediaID2, mediaID3},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-delete", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -127,7 +127,7 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
// Send invalid JSON
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-delete", bytes.NewBuffer([]byte("invalid json")))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-delete", bytes.NewBuffer([]byte("invalid json")))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -143,14 +143,18 @@ func TestMediaBulkOperations(t *testing.T) {
setup := setupTestServer(t)
req := map[string]interface{}{
"book_ids": []string{uuid.New().String()},
"updates": map[string]interface{}{
"tags": []string{"test"},
"media_item_updates": []map[string]interface{}{
{
"media_item_id": uuid.New().String(),
"updates": map[string]interface{}{
"tags": []string{"test"},
},
},
},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-update", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
client := &http.Client{}
@@ -167,14 +171,18 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
req := map[string]interface{}{
"book_ids": []string{},
"updates": map[string]interface{}{
"tags": []string{"test"},
"media_item_updates": []map[string]interface{}{
{
"media_item_id": "",
"updates": map[string]interface{}{
"tags": []string{"test"},
},
},
},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-update", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -192,14 +200,18 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
req := map[string]interface{}{
"book_ids": []string{"invalid-uuid"},
"updates": map[string]interface{}{
"tags": []string{"fiction", "test"},
"media_item_updates": []map[string]interface{}{
{
"media_item_id": "invalid-uuid",
"updates": map[string]interface{}{
"tags": []string{"fiction", "test"},
},
},
},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-update", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -224,19 +236,29 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
// Create test books
bookID1 := createTestMediaItemID(t, setup.Server, token)
bookID2 := createTestMediaItemID(t, setup.Server, token)
// Create test media items
mediaID1 := createTestMediaItemID(t, setup.Server, token)
mediaID2 := createTestMediaItemID(t, setup.Server, token)
req := map[string]interface{}{
"book_ids": []string{bookID1, bookID2},
"updates": map[string]interface{}{
"tags": []string{"fiction", "science-fiction", "test"},
"media_item_updates": []map[string]interface{}{
{
"media_item_id": mediaID1,
"updates": map[string]interface{}{
"tags": []string{"fiction", "science-fiction", "test"},
},
},
{
"media_item_id": mediaID2,
"updates": map[string]interface{}{
"tags": []string{"fiction", "science-fiction", "test"},
},
},
},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-update", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -263,18 +285,22 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
// Create test books
bookID1 := createTestMediaItemID(t, setup.Server, token)
// Create test media items
mediaID1 := createTestMediaItemID(t, setup.Server, token)
req := map[string]interface{}{
"book_ids": []string{bookID1},
"updates": map[string]interface{}{
"reading_status": "reading",
"media_item_updates": []map[string]interface{}{
{
"media_item_id": mediaID1,
"updates": map[string]interface{}{
"reading_status": "reading",
},
},
},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-update", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -296,20 +322,24 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
// Create test books
bookID1 := createTestMediaItemID(t, setup.Server, token)
// Create test media items
mediaID1 := createTestMediaItemID(t, setup.Server, token)
req := map[string]interface{}{
"book_ids": []string{bookID1},
"updates": map[string]interface{}{
"tags": []string{"test", "bulk-update"},
"reading_status": "to-read",
"rating": 4,
"media_item_updates": []map[string]interface{}{
{
"media_item_id": mediaID1,
"updates": map[string]interface{}{
"tags": []string{"test", "bulk-update"},
"reading_status": "to-read",
"rating": 4,
},
},
},
}
body, _ := json.Marshal(req)
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer(body))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-update", bytes.NewBuffer(body))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)
@@ -332,7 +362,7 @@ func TestMediaBulkOperations(t *testing.T) {
token := loginTestUser(t, setup.Server, setup.DB)
// Send invalid JSON
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/books/bulk-update", bytes.NewBuffer([]byte("invalid json")))
httpReq, _ := http.NewRequest("POST", setup.Server.URL+"/api/media-items/bulk-update", bytes.NewBuffer([]byte("invalid json")))
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+token)