feat(server): add GET /attachment/status with derived boxed qty
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -28,3 +28,59 @@ def test_categories_lists_active_only(client: TestClient, db: Session):
|
||||
assert "TEST_OFF" not in names
|
||||
# sorted by sort_order then name
|
||||
assert names.index("TEST_CERT") < names.index("TEST_EXTRA")
|
||||
|
||||
|
||||
def test_status_unknown_zongpai_is_undetermined(client: TestClient):
|
||||
resp = client.get(
|
||||
"/CargoTrace/attachment/status", params={"zongpai_no": "26BW0011"}
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["zongpai_no"] == "26BW0011"
|
||||
assert data["determination"] == "undetermined"
|
||||
assert data["items"] == []
|
||||
assert data["all_complete"] is False
|
||||
|
||||
|
||||
def test_status_invalid_zongpai(client: TestClient):
|
||||
resp = client.get(
|
||||
"/CargoTrace/attachment/status", params={"zongpai_no": "BAD"}
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert resp.json()["error_code"] == "INVALID_ZONGPAI"
|
||||
|
||||
|
||||
def test_status_reflects_config_and_boxed(client: TestClient, db: Session):
|
||||
cat_ids = _seed_categories(db)
|
||||
cert_id = cat_ids[0]
|
||||
# Plan: 检验证书 expected=80
|
||||
client.put(
|
||||
"/CargoTrace/attachment/config",
|
||||
json={
|
||||
"zongpai_no": "26BW0011",
|
||||
"determination": "has",
|
||||
"items": [{"category_id": cert_id, "expected_qty": 80}],
|
||||
},
|
||||
)
|
||||
# Box 30 of them
|
||||
client.post(
|
||||
"/CargoTrace/attachment/box",
|
||||
json={
|
||||
"zongpai_no": "26BW0011",
|
||||
"category_id": cert_id,
|
||||
"box_no": 921,
|
||||
"quantity": 30,
|
||||
},
|
||||
)
|
||||
resp = client.get(
|
||||
"/CargoTrace/attachment/status", params={"zongpai_no": "26BW0011"}
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["determination"] == "has"
|
||||
assert data["all_complete"] is False
|
||||
item = data["items"][0]
|
||||
assert item["category_id"] == cert_id
|
||||
assert item["expected_qty"] == 80
|
||||
assert item["boxed_qty"] == 30
|
||||
assert item["complete"] is False
|
||||
|
||||
Reference in New Issue
Block a user