| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- """Public feedback / suggestion / hotline / qrcode APIs."""
- from app.models.business import Feedback, Suggestion
- from app.services import feedback_service, suggestion_service
- from app.services.seed import seed_if_empty
- def test_submit_feedback(client):
- r = client.post(
- "/api/public/feedback",
- json={"fbType": "投诉", "content": "测试投诉内容"},
- )
- assert r.status_code == 200
- data = r.json()["data"]
- assert data["bizNo"].startswith("FK")
- assert data["id"]
- def test_feedback_requires_content(client):
- r = client.post("/api/public/feedback", json={"fbType": "投诉", "content": ""})
- assert r.status_code == 400
- def test_feedback_missing_content_is_400(client):
- r = client.post("/api/public/feedback", json={"fbType": "投诉"})
- assert r.status_code == 400
- body = r.json()
- assert body["code"] == 400
- assert "detail" not in body
- def test_get_hotline(client):
- assert client.get("/api/public/hotline").json()["code"] == 200
- def test_submit_suggestion(client):
- r = client.post(
- "/api/public/suggestion",
- json={"content": "测试建言内容"},
- )
- assert r.status_code == 200
- data = r.json()["data"]
- assert data["bizNo"].startswith("JY")
- assert data["id"]
- def test_suggestion_requires_content(client):
- r = client.post("/api/public/suggestion", json={"content": ""})
- assert r.status_code == 400
- def test_get_qrcode(client):
- r = client.get("/api/public/qrcode")
- assert r.status_code == 200
- body = r.json()
- assert body["code"] == 200
- assert "landUrl" in body["data"]
- def test_feedback_biz_no_daily_seq(client):
- r1 = client.post(
- "/api/public/feedback",
- json={"fbType": "表扬", "content": "第一条"},
- )
- r2 = client.post(
- "/api/public/feedback",
- json={"fbType": "表扬", "content": "第二条"},
- )
- n1 = r1.json()["data"]["bizNo"]
- n2 = r2.json()["data"]["bizNo"]
- assert n1[:-3] == n2[:-3]
- assert int(n2[-3:]) == int(n1[-3:]) + 1
- def test_hotline_camel_case_fields(client):
- data = client.get("/api/public/hotline").json()["data"]
- assert "phone" in data
- assert "workTime" in data
- assert "work_time" not in data
- def test_feedback_default_status_and_attachments(db_session):
- seed_if_empty(db_session)
- result = feedback_service.submit_feedback(
- db_session,
- fb_type="投诉",
- content="带附件投诉",
- attachment_urls=["/uploads/a.png", "/uploads/b.png"],
- )
- row = db_session.query(Feedback).filter(Feedback.id == result["id"]).one()
- assert row.status == "待处理"
- assert row.attachments == ["/uploads/a.png", "/uploads/b.png"]
- def test_suggestion_default_status(db_session):
- seed_if_empty(db_session)
- result = suggestion_service.submit_suggestion(
- db_session,
- content="建言默认状态",
- )
- row = db_session.query(Suggestion).filter(Suggestion.id == result["id"]).one()
- assert row.status == "待查阅"
|