diff --git a/frontend/templates/files.html b/frontend/templates/files.html
index bd9acec7..7b01274c 100644
--- a/frontend/templates/files.html
+++ b/frontend/templates/files.html
@@ -501,8 +501,13 @@
})
.then(response => {
if (!response.ok) {
- throw new Error('Failed to delete file');
+ return response.json().then(err => {
+ throw new Error(err.detail || 'Failed to delete file');
+ });
}
+ return response.json();
+ })
+ .then(data => {
// Reload the page to show updated file list
window.location.reload();
})
diff --git a/tests/test_bulk_operations.py b/tests/test_bulk_operations.py
index 97224d4d..cd7dc5b6 100644
--- a/tests/test_bulk_operations.py
+++ b/tests/test_bulk_operations.py
@@ -7,6 +7,44 @@ from app.models import FileRecord, ProcessingLog
from unittest.mock import patch, MagicMock
+@pytest.mark.integration
+@pytest.mark.requires_db
+class TestSingleFileOperations:
+ """Tests for single file operations."""
+
+ def test_single_file_delete_success(self, client: TestClient, db_session):
+ """Test deletion of a single file."""
+ # Create a sample file
+ file_record = FileRecord(
+ filehash="hash1",
+ original_filename="test.pdf",
+ local_filename="/tmp/test.pdf",
+ file_size=1024,
+ mime_type="application/pdf"
+ )
+ db_session.add(file_record)
+ db_session.commit()
+ file_id = file_record.id
+
+ # Delete the file
+ response = client.delete(f"/api/files/{file_id}")
+ assert response.status_code == 200
+ data = response.json()
+ assert data["status"] == "success"
+ assert f"File record {file_id} deleted successfully" in data["message"]
+
+ # Verify file is deleted
+ file_record = db_session.query(FileRecord).filter(FileRecord.id == file_id).first()
+ assert file_record is None
+
+ def test_single_file_delete_nonexistent(self, client: TestClient, db_session):
+ """Test deletion of a non-existent file."""
+ response = client.delete("/api/files/9999")
+ assert response.status_code == 404
+ data = response.json()
+ assert "not found" in data["detail"].lower()
+
+
@pytest.mark.integration
@pytest.mark.requires_db
class TestBulkOperations: