From c450f3579e1ee56609bb710a5907126eb46db765 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Wed, 3 Jun 2026 23:52:04 +0000 Subject: [PATCH] Upload tests/test_dashboard.py --- tests/test_dashboard.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_dashboard.py diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py new file mode 100644 index 0000000..6f276a2 --- /dev/null +++ b/tests/test_dashboard.py @@ -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