Upload tests/test_dashboard.py

This commit is contained in:
2026-06-03 23:52:04 +00:00
committed by leocrm-bot
parent 9f1187f667
commit c450f3579e
+36
View File
@@ -0,0 +1,36 @@
"""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())
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