test: cover webhook ingestion edge cases

This commit is contained in:
Christian Krakau-Louis
2026-05-22 23:53:36 +02:00
parent 302159aeb6
commit 88af60ed2e
2 changed files with 165 additions and 0 deletions
+30
View File
@@ -2132,6 +2132,36 @@ class TestTriggerPollEndpoint:
finally:
main_app.dependency_overrides.clear()
def test_trigger_poll_with_no_enabled_sources(self):
"""With no enabled sources, the endpoint returns an empty-success response."""
from app.core.security import require_admin_auth
from app.main import app as main_app
async def mock_auth():
return {"auth_type": "api_key"}
main_app.dependency_overrides[require_admin_auth] = mock_auth
try:
mock_db = MagicMock()
mock_db.query.return_value.filter.return_value.all.return_value = []
with TestClient(main_app) as tc:
with patch("app.main.SessionLocal", return_value=mock_db):
resp = tc.post("/api/v1/admin/trigger-poll?days=14")
assert resp.status_code == 200
data = resp.json()
assert data == {
"success": True,
"message": "No enabled mail sources configured.",
"sources_polled": 0,
"days": 14,
"authenticated_by": "api_key",
}
finally:
main_app.dependency_overrides.clear()
# ---------------------------------------------------------------------------
# Pytest marker to avoid warnings for test methods without assertions