from app.services.shipping_notice.parse_summary import format_parse_summary def test_format_parse_summary_single_line(): msg = format_parse_summary( task_no="SN-20260604-7249E4D7", po_number="16754796", ship_to="Wistron Corporation, Czech Republic", lines=[ { "part_number": "504-010213-001", "reservation_id": "1000140351", "qty": 9, "uom": "PCS", "unit_price": 1607.72, "amount": 14469.48, "currency": "USD", "required_date": "2026-06-15", } ], ) assert "【发货通知解析确认】任务编号:SN-20260604-7249E4D7" in msg assert "| 采购单号 | 16754796 |" in msg assert "| 预订单号 | 1000140351 |" in msg assert "| 内部料号 | 504-010213-001 |" in msg po_idx = msg.index("| 采购单号 |") rid_idx = msg.index("| 预订单号 |") part_idx = msg.index("| 内部料号 |") assert po_idx < rid_idx < part_idx assert "| 数量 | 9 PCS |" in msg assert "| 单价 | $1,607.72 |" in msg assert "| 金额 | $14,469.48 |" in msg assert "| 需求日期 | 2026-06-15 |" in msg assert "Wistron Corporation, Czech Republic" in msg assert "请确认以上信息是否正确?" in msg assert "待从任务中获取" not in msg def test_format_parse_summary_multiple_lines(): msg = format_parse_summary( task_no="SN-1", po_number="PO-1", lines=[ {"part_number": "A", "qty": 1, "reservation_id": "R1"}, {"part_number": "B", "qty": 2, "reservation_id": "R2"}, ], ) assert "【明细 1】" in msg assert "【明细 2】" in msg assert "采购单号:PO-1" in msg def test_format_parse_summary_includes_warnings(): msg = format_parse_summary( task_no="SN-1", lines=[{"part_number": "A", "qty": 1}], warnings=["订单行未解析到 Reservation ID"], low_confidence=True, ) assert "订单行未解析到 Reservation ID" in msg assert "解析置信度较低" in msg