fix(07): add status field to _doc_to_dict + regression test
DocumentCard classification_failed badge requires doc.status from the API list endpoint. _doc_to_dict was omitting the field; this fix adds it and adds a regression test that would have caught the omission. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3b11b9a596
commit
76ebc3e96e
@@ -61,6 +61,7 @@ def _doc_to_dict(doc: Document, topic_names: list) -> dict:
|
||||
"topics": topic_names,
|
||||
"created_at": doc.created_at.isoformat() if doc.created_at else None,
|
||||
"classified_at": doc.updated_at.isoformat() if doc.status == "classified" else None,
|
||||
"status": doc.status,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -79,6 +79,33 @@ async def test_list_documents_filter_by_topic(async_client, auth_user, db_sessio
|
||||
assert resp2.json()["total"] == 0
|
||||
|
||||
|
||||
async def test_list_documents_includes_status(async_client, auth_user, db_session):
|
||||
"""GET /api/documents items must include a 'status' field (regression: _doc_to_dict omitted it)."""
|
||||
import uuid as _uuid
|
||||
from db.models import Document
|
||||
|
||||
doc_id = _uuid.uuid4()
|
||||
doc = Document(
|
||||
id=doc_id,
|
||||
user_id=auth_user["user"].id,
|
||||
filename="status_test.txt",
|
||||
content_type="text/plain",
|
||||
size_bytes=50,
|
||||
storage_backend="minio",
|
||||
status="classification_failed",
|
||||
object_key=f"{auth_user['user'].id}/{doc_id}/{_uuid.uuid4()}.txt",
|
||||
)
|
||||
db_session.add(doc)
|
||||
await db_session.commit()
|
||||
|
||||
resp = await async_client.get("/api/documents", headers=auth_user["headers"])
|
||||
assert resp.status_code == 200
|
||||
items = resp.json()["items"]
|
||||
assert len(items) == 1
|
||||
assert "status" in items[0], "status field missing from document list item"
|
||||
assert items[0]["status"] == "classification_failed"
|
||||
|
||||
|
||||
async def test_get_document(async_client, auth_user, db_session):
|
||||
"""GET /api/documents/{id} returns metadata for an existing document."""
|
||||
import uuid as _uuid
|
||||
|
||||
Reference in New Issue
Block a user