46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
from app.services.shipping_notice.match import match_notice_lines
|
|
from app.services.shipping_notice.reservation_id import (
|
|
is_valid_reservation_id,
|
|
normalize_reservation_id,
|
|
validated_reservation_id,
|
|
)
|
|
|
|
|
|
def test_match_numeric_reservation_id():
|
|
notice = [{"order-part": "D4-A08AR12000002", "order-reservation": "1000140351", "__required_qty": 2}]
|
|
inventory = [{"101": "D4-A08AR12000002", "102": "1000140351", "103": 3}]
|
|
status, results, _ = match_notice_lines(
|
|
notice, inventory,
|
|
match_keys=[
|
|
{'order_field_id': 'order-part', 'inventory_field_id': '101'},
|
|
{'order_field_id': 'order-reservation', 'inventory_field_id': '102'},
|
|
],
|
|
quantity_field_id='103',
|
|
)
|
|
assert status == "fulfillable"
|
|
assert results[0]["available_qty"] == 3
|
|
|
|
|
|
def test_normalize_reservation_id_string():
|
|
assert normalize_reservation_id("1000140351") == "1000140351"
|
|
|
|
|
|
def test_reservation_contract_only_accepts_five_or_ten_digits():
|
|
"""硬契约只接受 5 位或 10 位纯数字 Reservation ID。"""
|
|
assert not is_valid_reservation_id("1f1a682dfdc446a393415dee93eb36ce")
|
|
assert validated_reservation_id("1f1a682dfdc446a393415dee93eb36ce") == ""
|
|
assert is_valid_reservation_id("12345")
|
|
assert is_valid_reservation_id("3000092917")
|
|
assert not is_valid_reservation_id("123456")
|
|
assert not is_valid_reservation_id("AWS-311")
|
|
assert not is_valid_reservation_id("R-1")
|
|
assert not is_valid_reservation_id("12345678901", numeric_only=True)
|
|
|
|
|
|
def test_reservation_gate_blocks_empty_and_malformed_order_lines():
|
|
"""空订单或畸形行都不能被视为 Reservation 门禁通过。"""
|
|
from app.services.shipping_notice.reservation_gate import reservation_gate_issues
|
|
|
|
assert reservation_gate_issues([])[0]["reason"] == "missing_order_lines"
|
|
assert reservation_gate_issues(["invalid-line"])[0]["reason"] == "invalid_order_line"
|