templates: support include_total for search and categories endpoints; update docs; add tests

This commit is contained in:
HotSwapp
2025-08-15 15:06:45 -05:00
parent e3a279dba7
commit 006ef3d7b1
3 changed files with 43 additions and 6 deletions

View File

@@ -247,6 +247,16 @@ def test_templates_search_pagination_and_sorting(client: TestClient):
# We can't assert exact order of timestamps easily; just ensure we got results
assert isinstance(resp.json(), list) and len(resp.json()) >= 5
# include_total=true returns object with items and total
resp = client.get(
"/api/templates/search",
params={"sort_by": "name", "sort_dir": "asc", "include_total": True},
)
assert resp.status_code == 200, resp.text
data = resp.json()
assert isinstance(data, dict) and "items" in data and "total" in data
assert isinstance(data["items"], list) and isinstance(data["total"], int)
def test_templates_search_active_filtering(client: TestClient):
# Create two templates, mark one inactive directly
@@ -373,6 +383,13 @@ def test_templates_categories_listing(client: TestClient):
assert resp.status_code == 200
rows_all = resp.json()
by_cat_all = {r["category"]: r["count"] for r in rows_all}
# include_total=true shape
resp = client.get("/api/templates/categories", params={"include_total": True, "active_only": False})
assert resp.status_code == 200
data = resp.json()
assert isinstance(data, dict) and "items" in data and "total" in data
assert isinstance(data["items"], list) and isinstance(data["total"], int)
assert by_cat_all.get("K1", 0) >= 2
assert by_cat_all.get("K2", 0) >= 1