37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""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
|