"""T3.7 行为助推引擎测试。""" import pytest from fastapi.testclient import TestClient class TestNudgesList: """助推记录列表接口测试。""" def test_list_nudges_empty(self, client: TestClient, auth_headers: dict): """无记录时应返回空列表。""" resp = client.get("/api/v1/nudges", headers=auth_headers) assert resp.status_code == 200 assert isinstance(resp.json()["data"], list) def test_list_nudges_with_company_filter(self, client: TestClient, auth_headers: dict, company_id: str): """指定企业 ID 过滤。""" resp = client.get(f"/api/v1/nudges?company_id={company_id}", headers=auth_headers) assert resp.status_code == 200 assert isinstance(resp.json()["data"], list) def test_list_nudges_no_auth(self, client: TestClient): """未认证应返回 401。""" resp = client.get("/api/v1/nudges") assert resp.status_code == 401 class TestNudgeSelect: """AI 助推策略选择接口测试。""" def test_select_nudge_success(self, client: TestClient, auth_headers: dict): """AI 选择助推策略。""" resp = client.post( "/api/v1/nudges/select", json={"context": "企业连续 2 个月未提交月报,创始人积极性下降"}, headers=auth_headers, ) assert resp.status_code == 200 assert isinstance(resp.json()["data"], dict) def test_select_nudge_no_auth(self, client: TestClient): """未认证应返回 401。""" resp = client.post("/api/v1/nudges/select", json={}) assert resp.status_code == 401 def test_select_nudge_empty_context(self, client: TestClient, auth_headers: dict): """空上下文应正常返回。""" resp = client.post( "/api/v1/nudges/select", json={"context": ""}, headers=auth_headers, ) assert resp.status_code == 200