"""Swagger 模块 11(经营)— 真实联调(客户/订单绑定真实 roomId)""" from __future__ import annotations import uuid import pytest pytestmark = [pytest.mark.integration, pytest.mark.qiwei_live] @pytest.fixture(scope="module") def m11_customer(api_session, live_room_id): suffix = uuid.uuid4().hex[:8] customer = api_session.assert_success( api_session.post( "/sales/customers", json={ "name": f"联调客户_{suffix}", "phone": f"138{suffix[:8]}", "source": "group", "roomId": live_room_id, }, ), status=201, ) return {"customer": customer, "room_id": live_room_id} def test_m11_leads_create_and_list(api, uid): lead = api.assert_success( api.post( "/sales/leads", json={ "salespersonId": 1, "recordDate": "2026-05-21", "addCount": 3, "remark": f"live-{uid}", }, ), status=201, ) assert lead["addCount"] == 3 listed = api.assert_success(api.get("/sales/leads")) assert any(l.get("remark") == f"live-{uid}" for l in listed) def test_m11_orders_create_and_list(api, m11_customer, uid): cust_id = m11_customer["customer"]["id"] order = api.assert_success( api.post( "/sales/orders", json={ "salespersonId": 1, "customerId": cust_id, "amount": 88000, "orderDate": "2026-05-20", "source": "group", "roomId": m11_customer["room_id"], }, ), status=201, ) assert order["roomId"] == m11_customer["room_id"] listed = api.assert_success(api.get("/sales/orders")) assert any(o["id"] == order["id"] for o in listed) def test_m11_customers_list(api, m11_customer): listed = api.assert_success(api.get("/sales/customers")) assert any(c["id"] == m11_customer["customer"]["id"] for c in listed) def test_m11_customer_detail(api, m11_customer): cid = m11_customer["customer"]["id"] detail = api.assert_success(api.get(f"/sales/customers/{cid}")) assert detail["roomId"] == m11_customer["room_id"] def test_m11_customer_update(api, m11_customer): cid = m11_customer["customer"]["id"] updated = api.assert_success( api.put(f"/sales/customers/{cid}", json={"remark": "模块11联调"}) ) assert updated.get("remark") == "模块11联调" def test_m11_follow_ups(api, m11_customer): cid = m11_customer["customer"]["id"] follow = api.assert_success( api.post( f"/sales/customers/{cid}/follow-ups", json={ "customerId": cid, "followerId": 1, "followDate": "2026-05-21", "method": "wechat", "content": "真实群跟进", }, ), status=201, ) assert follow["customerId"] == cid listed = api.assert_success(api.get(f"/sales/customers/{cid}/follow-ups")) assert len(listed) >= 1 def test_m11_live_stats(api, uid): stat = api.assert_success( api.post( "/sales/live-stats", json={ "liveSessionId": f"live-session-{uid}", "title": f"联调直播_{uid}", "liveDate": "2026-05-21", "viewerCount": 256, }, ), status=201, ) assert stat["viewerCount"] == 256 listed = api.assert_success(api.get("/sales/live-stats")) assert any(s["id"] == stat["id"] for s in listed)