test_public_feedback.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """Public feedback / suggestion / hotline / qrcode APIs."""
  2. from app.models.business import Feedback, Suggestion
  3. from app.services import feedback_service, suggestion_service
  4. from app.services.seed import seed_if_empty
  5. def test_submit_feedback(client):
  6. r = client.post(
  7. "/api/public/feedback",
  8. json={"fbType": "投诉", "content": "测试投诉内容"},
  9. )
  10. assert r.status_code == 200
  11. data = r.json()["data"]
  12. assert data["bizNo"].startswith("FK")
  13. assert data["id"]
  14. def test_feedback_requires_content(client):
  15. r = client.post("/api/public/feedback", json={"fbType": "投诉", "content": ""})
  16. assert r.status_code == 400
  17. def test_feedback_missing_content_is_400(client):
  18. r = client.post("/api/public/feedback", json={"fbType": "投诉"})
  19. assert r.status_code == 400
  20. body = r.json()
  21. assert body["code"] == 400
  22. assert "detail" not in body
  23. def test_get_hotline(client):
  24. assert client.get("/api/public/hotline").json()["code"] == 200
  25. def test_submit_suggestion(client):
  26. r = client.post(
  27. "/api/public/suggestion",
  28. json={"content": "测试建言内容"},
  29. )
  30. assert r.status_code == 200
  31. data = r.json()["data"]
  32. assert data["bizNo"].startswith("JY")
  33. assert data["id"]
  34. def test_suggestion_requires_content(client):
  35. r = client.post("/api/public/suggestion", json={"content": ""})
  36. assert r.status_code == 400
  37. def test_get_qrcode(client):
  38. r = client.get("/api/public/qrcode")
  39. assert r.status_code == 200
  40. body = r.json()
  41. assert body["code"] == 200
  42. assert "landUrl" in body["data"]
  43. def test_feedback_biz_no_daily_seq(client):
  44. r1 = client.post(
  45. "/api/public/feedback",
  46. json={"fbType": "表扬", "content": "第一条"},
  47. )
  48. r2 = client.post(
  49. "/api/public/feedback",
  50. json={"fbType": "表扬", "content": "第二条"},
  51. )
  52. n1 = r1.json()["data"]["bizNo"]
  53. n2 = r2.json()["data"]["bizNo"]
  54. assert n1[:-3] == n2[:-3]
  55. assert int(n2[-3:]) == int(n1[-3:]) + 1
  56. def test_hotline_camel_case_fields(client):
  57. data = client.get("/api/public/hotline").json()["data"]
  58. assert "phone" in data
  59. assert "workTime" in data
  60. assert "work_time" not in data
  61. def test_feedback_default_status_and_attachments(db_session):
  62. seed_if_empty(db_session)
  63. result = feedback_service.submit_feedback(
  64. db_session,
  65. fb_type="投诉",
  66. content="带附件投诉",
  67. attachment_urls=["/uploads/a.png", "/uploads/b.png"],
  68. )
  69. row = db_session.query(Feedback).filter(Feedback.id == result["id"]).one()
  70. assert row.status == "待处理"
  71. assert row.attachments == ["/uploads/a.png", "/uploads/b.png"]
  72. def test_suggestion_default_status(db_session):
  73. seed_if_empty(db_session)
  74. result = suggestion_service.submit_suggestion(
  75. db_session,
  76. content="建言默认状态",
  77. )
  78. row = db_session.query(Suggestion).filter(Suggestion.id == result["id"]).one()
  79. assert row.status == "待查阅"