test_pl_customer_stop_pref_service.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """客户装/送货默认记忆:条目合并规则"""
  2. from app.services.pl_customer_stop_pref_service import build_stop_pref_upsert_items
  3. def test_build_items_skips_empty_customer():
  4. items = build_stop_pref_upsert_items(
  5. load={"customer_id": "", "address": "A"},
  6. deliveries=[{"customer_id": "c1", "address": "D1", "contact": "1", "notes": "n"}],
  7. )
  8. assert len(items) == 1
  9. assert items[0]["stop_type"] == "delivery"
  10. assert items[0]["customer_id"] == "c1"
  11. def test_build_items_load_and_delivery_independent():
  12. items = build_stop_pref_upsert_items(
  13. load={
  14. "customer_id": "c1",
  15. "customer_name": "甲",
  16. "address": "装址",
  17. "lng": 1.1,
  18. "lat": 2.2,
  19. "contact": "装联",
  20. "notes": "装注",
  21. },
  22. deliveries=[
  23. {
  24. "customer_id": "c1",
  25. "customer_name": "甲",
  26. "address": "送址",
  27. "contact": "送联",
  28. "notes": "送注",
  29. }
  30. ],
  31. )
  32. assert len(items) == 2
  33. by_type = {i["stop_type"]: i for i in items}
  34. assert by_type["load"]["address"] == "装址"
  35. assert by_type["delivery"]["address"] == "送址"
  36. def test_build_items_same_delivery_customer_last_wins():
  37. items = build_stop_pref_upsert_items(
  38. load=None,
  39. deliveries=[
  40. {"customer_id": "c1", "address": "第一段", "contact": "a", "notes": "1"},
  41. {"customer_id": "c2", "address": "别家", "contact": "b", "notes": "2"},
  42. {"customer_id": "c1", "address": "最后段", "contact": "c", "notes": "3"},
  43. ],
  44. )
  45. delivery_c1 = [i for i in items if i["stop_type"] == "delivery" and i["customer_id"] == "c1"]
  46. assert len(delivery_c1) == 1
  47. assert delivery_c1[0]["address"] == "最后段"
  48. assert delivery_c1[0]["contact"] == "c"