test_11_sales.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. """§11 经营数据补录"""
  2. import pytest
  3. pytestmark = pytest.mark.integration
  4. def test_sales_flow(api, uid):
  5. customer = api.assert_success(
  6. api.post(
  7. "/sales/customers",
  8. json={
  9. "name": f"客户{uid}",
  10. "phone": f"139{uid[:8]}",
  11. "source": "group",
  12. "roomId": f"room-{uid}",
  13. },
  14. ),
  15. status=201,
  16. )
  17. cust_id = customer["id"]
  18. follow = api.assert_success(
  19. api.post(
  20. f"/sales/customers/{cust_id}/follow-ups",
  21. json={
  22. "customerId": cust_id,
  23. "followerId": 1,
  24. "followDate": "2026-05-21",
  25. "method": "call",
  26. "content": "首次跟进",
  27. },
  28. ),
  29. status=201,
  30. )
  31. assert follow["customerId"] == cust_id
  32. follows = api.assert_success(api.get(f"/sales/customers/{cust_id}/follow-ups"))
  33. assert len(follows) >= 1
  34. lead = api.assert_success(
  35. api.post(
  36. "/sales/leads",
  37. json={
  38. "salespersonId": 1,
  39. "recordDate": "2026-05-21",
  40. "addCount": 2,
  41. "remark": uid,
  42. },
  43. ),
  44. status=201,
  45. )
  46. assert lead["addCount"] == 2
  47. order = api.assert_success(
  48. api.post(
  49. "/sales/orders",
  50. json={
  51. "salespersonId": 1,
  52. "customerId": cust_id,
  53. "amount": 100000,
  54. "orderDate": "2026-05-20",
  55. "source": "group",
  56. "roomId": f"room-{uid}",
  57. },
  58. ),
  59. status=201,
  60. )
  61. assert order["amount"] == 100000
  62. live = api.assert_success(
  63. api.post(
  64. "/sales/live-stats",
  65. json={
  66. "liveSessionId": f"live-{uid}",
  67. "title": f"直播{uid}",
  68. "liveDate": "2026-05-21",
  69. "viewerCount": 100,
  70. },
  71. ),
  72. status=201,
  73. )
  74. assert live["viewerCount"] == 100
  75. api.assert_success(api.get("/sales/leads"))
  76. api.assert_success(api.get("/sales/orders"))
  77. api.assert_success(api.get("/sales/customers"))
  78. api.assert_success(api.get("/sales/live-stats"))