Files
leocrm/tests/test_dashboard.py
T

39 lines
1.3 KiB
Python
Raw Normal View History

2026-06-03 23:52:04 +00:00
"""Tests for FR-7 (Dashboard: KPIs + activity feed)."""
from __future__ import annotations
import pytest
from httpx import AsyncClient
@pytest.mark.asyncio
async def test_kpis(client: AsyncClient, seed_data: dict) -> None:
resp = await client.get("/api/v1/dashboard/kpis", headers=seed_data["headers"])
assert resp.status_code == 200, resp.text
body = resp.json()
assert {"open_deals_count", "pipeline_value", "won_this_month", "conversion_rate"} <= set(
body.keys()
)
2026-06-03 23:52:04 +00:00
assert isinstance(body["open_deals_count"], int)
assert isinstance(body["pipeline_value"], (int, float))
assert isinstance(body["won_this_month"], int)
assert isinstance(body["conversion_rate"], (int, float))
@pytest.mark.asyncio
async def test_activity_feed(client: AsyncClient, seed_data: dict) -> None:
resp = await client.get("/api/v1/dashboard/feed?limit=20", headers=seed_data["headers"])
assert resp.status_code == 200, resp.text
body = resp.json()
assert isinstance(body, list)
assert len(body) >= 1
# Items are sorted by created_at desc (most recent first)
if len(body) >= 2:
assert body[0]["created_at"] >= body[-1]["created_at"]
@pytest.mark.asyncio
async def test_dashboard_requires_auth(client: AsyncClient) -> None:
resp = await client.get("/api/v1/dashboard/kpis")
assert resp.status_code == 401