Fix single file deletion frontend to parse JSON response properly

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-07 17:53:12 +00:00
parent 082d447e72
commit 77678f6368
2 changed files with 44 additions and 1 deletions
+6 -1
View File
@@ -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();
})
+38
View File
@@ -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: