2026-09-10 10:58:43 +08:00
|
|
|
|
"""
|
2026-09-18 13:50:19 +08:00
|
|
|
|
婚恋咨询 / 婚前辅导 E2E(咨询主流程)。
|
|
|
|
|
|
|
|
|
|
|
|
迁移说明:原文件依赖 3 个环境变量(import 期即 KeyError → 从未被收集执行),
|
|
|
|
|
|
并直连 psycopg2 校验通知落库,且用不存在的固定 ID 做断言。
|
|
|
|
|
|
现统一改为 conftest fixture + 真实 API;数据库断言交后端集成测试,E2E 只走 HTTP。
|
2026-09-10 10:58:43 +08:00
|
|
|
|
"""
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
2026-09-18 13:50:19 +08:00
|
|
|
|
pytestmark = pytest.mark.e2e
|
2026-09-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-09-18 13:50:19 +08:00
|
|
|
|
def test_counseling_intro_lists_guidance_types(api, user_token):
|
|
|
|
|
|
data = api.ok("GET", "/counseling/services/intro", token=user_token)
|
|
|
|
|
|
assert isinstance(data, list) and len(data) >= 2, f"咨询介绍异常:{data}"
|
|
|
|
|
|
types = {item.get("type") for item in data}
|
|
|
|
|
|
for expected in ("relationship_guidance", "premarital_guidance"):
|
|
|
|
|
|
assert expected in types, f"咨询介绍缺少 {expected}:{sorted(types)}"
|
2026-09-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-09-18 13:50:19 +08:00
|
|
|
|
def test_create_counseling_is_user_self_and_pending(api, user_token):
|
|
|
|
|
|
"""用户端创建咨询:source 必须恒为 user_self,不可由请求体伪造。"""
|
|
|
|
|
|
data = api.ok(
|
|
|
|
|
|
"POST",
|
|
|
|
|
|
"/counseling/services",
|
|
|
|
|
|
token=user_token,
|
|
|
|
|
|
json={"serviceType": "relationship_guidance", "userRequestSummary": "恋爱沟通困难"},
|
2026-09-10 10:58:43 +08:00
|
|
|
|
)
|
|
|
|
|
|
assert data["status"] == "pending"
|
|
|
|
|
|
assert data["serviceType"] == "relationship_guidance"
|
2026-09-18 13:50:19 +08:00
|
|
|
|
assert data["requestSource"] == "user_self", f"来源被污染:{data}"
|
2026-09-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-09-18 13:50:19 +08:00
|
|
|
|
def test_my_counseling_list_is_accessible(api, user_token):
|
|
|
|
|
|
api.ok("POST", "/counseling/services", token=user_token,
|
|
|
|
|
|
json={"serviceType": "relationship_guidance", "userRequestSummary": "列表用例"})
|
|
|
|
|
|
data = api.ok("GET", "/counseling/services", token=user_token)
|
|
|
|
|
|
assert isinstance(data, list)
|
2026-09-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-09-18 13:50:19 +08:00
|
|
|
|
def test_cancel_counseling(api, user_token):
|
|
|
|
|
|
created = api.ok(
|
|
|
|
|
|
"POST",
|
|
|
|
|
|
"/counseling/services",
|
|
|
|
|
|
token=user_token,
|
|
|
|
|
|
json={"serviceType": "emotional_support", "userRequestSummary": "测试取消"},
|
2026-09-10 10:58:43 +08:00
|
|
|
|
)
|
2026-09-18 13:50:19 +08:00
|
|
|
|
cancelled = api.ok(
|
|
|
|
|
|
"POST", f"/counseling/services/{created['id']}/cancel", token=user_token
|
2026-09-10 10:58:43 +08:00
|
|
|
|
)
|
2026-09-18 13:50:19 +08:00
|
|
|
|
assert cancelled["status"] == "cancelled", f"取消后状态错误:{cancelled}"
|
2026-09-10 10:58:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-09-18 13:50:19 +08:00
|
|
|
|
def test_counselor_assigned_list_is_scoped(api, operator_token):
|
|
|
|
|
|
"""INV-012:咨询师只能看到分配给自己的服务(列表必须可访问且为列表)。"""
|
|
|
|
|
|
token = operator_token("e2e_counselor")
|
|
|
|
|
|
data = api.ok("GET", "/counseling/services/operator/assigned", token=token)
|
|
|
|
|
|
assert isinstance(data, list)
|