f868414966
- 新增反馈审核字段和迁移,支持 pending/adopted/rejected、未采纳原因和采纳金币 - 增加用户端反馈历史 records 接口和 admin 采纳/拒绝接口 - 采纳时同事务写状态、金币流水和审计日志,拦截重复审核 - 验证:pytest tests/test_feedback.py tests/test_admin_write.py tests/test_admin_read.py --------- Co-authored-by: lowmaster-chen <1119780489@qq.com> Reviewed-on: #66 Co-authored-by: chenshuobo <chenshuobo@wonderable.ai> Co-committed-by: chenshuobo <chenshuobo@wonderable.ai>
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
"""用户反馈接口测试。"""
|
|
from __future__ import annotations
|
|
|
|
from app.db.session import SessionLocal
|
|
from app.models.feedback import Feedback
|
|
from app.repositories import user as user_repo
|
|
|
|
|
|
def _login(client, phone: str) -> str:
|
|
client.post("/api/v1/auth/sms/send", json={"phone": phone})
|
|
r = client.post("/api/v1/auth/sms/login", json={"phone": phone, "code": "123456"})
|
|
assert r.status_code == 200, r.text
|
|
return r.json()["access_token"]
|
|
|
|
|
|
def test_feedback_records_empty_returns_200(client) -> None:
|
|
token = _login(client, "13622000001")
|
|
|
|
r = client.get("/api/v1/feedback/records", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
assert r.status_code == 200, r.text
|
|
assert r.json() == {
|
|
"records": [],
|
|
"counts": {"all": 0, "pending": 0, "adopted": 0, "rejected": 0},
|
|
}
|
|
|
|
|
|
def test_feedback_config_returns_default(client) -> None:
|
|
token = _login(client, "13622000002")
|
|
|
|
r = client.get("/api/v1/feedback/config", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
assert r.status_code == 200, r.text
|
|
body = r.json()
|
|
assert body["enabled"] is True
|
|
assert body["group_name"] == "傻瓜比价官方群"
|
|
|
|
|
|
def test_feedback_records_maps_existing_statuses(client) -> None:
|
|
phone = "13622000003"
|
|
token = _login(client, phone)
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
user = user_repo.get_user_by_phone(db, phone)
|
|
assert user is not None
|
|
db.add(Feedback(user_id=user.id, content="待处理反馈", contact="", status="pending"))
|
|
db.add(
|
|
Feedback(
|
|
user_id=user.id,
|
|
content="已采纳反馈",
|
|
contact="",
|
|
status="adopted",
|
|
reward_coins=800,
|
|
)
|
|
)
|
|
db.add(
|
|
Feedback(
|
|
user_id=user.id,
|
|
content="未采纳反馈",
|
|
contact="",
|
|
status="rejected",
|
|
reject_reason="暂未提供可复现信息",
|
|
)
|
|
)
|
|
db.commit()
|
|
finally:
|
|
db.close()
|
|
|
|
r = client.get("/api/v1/feedback/records", headers={"Authorization": f"Bearer {token}"})
|
|
|
|
assert r.status_code == 200, r.text
|
|
body = r.json()
|
|
assert body["counts"] == {"all": 3, "pending": 1, "adopted": 1, "rejected": 1}
|
|
by_status = {item["status"]: item for item in body["records"]}
|
|
assert by_status["adopted"]["reward_coins"] == 800
|
|
assert by_status["rejected"]["reject_reason"] == "暂未提供可复现信息"
|