feat(pl): add customer stop pref service and unit tests
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
bd682288f9
commit
e56d227fe8
2 files changed
+222
No files matched your search
@@ -0,0 +1,54 @@
|
||||
"""客户装/送货默认记忆:条目合并规则"""
|
||||
from app.services.pl_customer_stop_pref_service import build_stop_pref_upsert_items
|
||||
|
||||
|
||||
def test_build_items_skips_empty_customer():
|
||||
items = build_stop_pref_upsert_items(
|
||||
load={"customer_id": "", "address": "A"},
|
||||
deliveries=[{"customer_id": "c1", "address": "D1", "contact": "1", "notes": "n"}],
|
||||
)
|
||||
assert len(items) == 1
|
||||
assert items[0]["stop_type"] == "delivery"
|
||||
assert items[0]["customer_id"] == "c1"
|
||||
|
||||
|
||||
def test_build_items_load_and_delivery_independent():
|
||||
items = build_stop_pref_upsert_items(
|
||||
load={
|
||||
"customer_id": "c1",
|
||||
"customer_name": "甲",
|
||||
"address": "装址",
|
||||
"lng": 1.1,
|
||||
"lat": 2.2,
|
||||
"contact": "装联",
|
||||
"notes": "装注",
|
||||
},
|
||||
deliveries=[
|
||||
{
|
||||
"customer_id": "c1",
|
||||
"customer_name": "甲",
|
||||
"address": "送址",
|
||||
"contact": "送联",
|
||||
"notes": "送注",
|
||||
}
|
||||
],
|
||||
)
|
||||
assert len(items) == 2
|
||||
by_type = {i["stop_type"]: i for i in items}
|
||||
assert by_type["load"]["address"] == "装址"
|
||||
assert by_type["delivery"]["address"] == "送址"
|
||||
|
||||
|
||||
def test_build_items_same_delivery_customer_last_wins():
|
||||
items = build_stop_pref_upsert_items(
|
||||
load=None,
|
||||
deliveries=[
|
||||
{"customer_id": "c1", "address": "第一段", "contact": "a", "notes": "1"},
|
||||
{"customer_id": "c2", "address": "别家", "contact": "b", "notes": "2"},
|
||||
{"customer_id": "c1", "address": "最后段", "contact": "c", "notes": "3"},
|
||||
],
|
||||
)
|
||||
delivery_c1 = [i for i in items if i["stop_type"] == "delivery" and i["customer_id"] == "c1"]
|
||||
assert len(delivery_c1) == 1
|
||||
assert delivery_c1[0]["address"] == "最后段"
|
||||
assert delivery_c1[0]["contact"] == "c"
|
||||
Reference in new issue
Block a user