"""Tests for tiny helpers in app.routers.api.""" from __future__ import annotations import pytest pytest.importorskip("fastapi") pytest.importorskip("sqlalchemy") from datetime import datetime, timedelta, timezone from app.routers.api import _fmt_age, _md_to_html def test_fmt_age_none(): assert _fmt_age(datetime.now(timezone.utc), None) == "—" def test_fmt_age_units(): now = datetime(2026, 5, 15, 12, 0, tzinfo=timezone.utc) assert _fmt_age(now, now - timedelta(seconds=30)) == "30s" assert _fmt_age(now, now - timedelta(minutes=5)) == "5m" assert _fmt_age(now, now - timedelta(hours=3)) == "3h" assert _fmt_age(now, now - timedelta(days=2)) == "2d" def test_md_to_html_headers_and_bold(): src = "## Section one\n\nBody text with **bold** word.\n\n## Section two\n\nMore." out = _md_to_html(src) assert "
" in out
def test_md_to_html_preserves_line_breaks_inside_block():
src = "Line one\nLine two"
out = _md_to_html(src)
assert "Line one
Line two" in out