From 76ebc3e96eca58d939c546452b87240a84d30ef7 Mon Sep 17 00:00:00 2001 From: curo1305 Date: Fri, 5 Jun 2026 09:30:03 +0200 Subject: [PATCH] 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 --- backend/services/storage.py | 1 + backend/tests/test_documents.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/backend/services/storage.py b/backend/services/storage.py index 70f15da..f96d95f 100644 --- a/backend/services/storage.py +++ b/backend/services/storage.py @@ -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, } diff --git a/backend/tests/test_documents.py b/backend/tests/test_documents.py index ae187c1..667a158 100644 --- a/backend/tests/test_documents.py +++ b/backend/tests/test_documents.py @@ -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