Skip to content

Commit 0c63fd3

Browse files
authored
Update shipment on cancellation (#33)
1 parent 505f0ce commit 0c63fd3

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/scaup/crud/shipments.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,12 @@ def get_shipment_request(shipmentId: int):
304304

305305

306306
def handle_callback(shipment_id: int, callback_body: StatusUpdate):
307+
columns: dict[str, str | None] = {
308+
"status": callback_body.status if callback_body.status != "CREATED" else "Pickup Cancelled"
309+
}
310+
307311
updated_shipment = inner_db.session.scalar(
308-
update(Shipment).returning(Shipment).filter_by(id=shipment_id).values({"status": callback_body.status})
312+
update(Shipment).returning(Shipment).filter_by(id=shipment_id).values(columns)
309313
)
310314

311315
inner_db.session.commit()

src/scaup/models/shipments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class ShipmentExternal(BaseExternal):
7979

8080
class StatusUpdate(BaseModel):
8181
origin_url: str
82-
journey_type: str
82+
journey_type: str | None = None
8383
status: str
84-
tracking_number: str
84+
tracking_number: str | None = None
8585
pickup_confirmation_code: str | None = None
8686
pickup_confirmation_timestamp: datetime | None

tests/shipments/test_update_status.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def test_post(client):
8-
"""Should get shipment details as tree of generic items"""
8+
"""Should update shipment status"""
99
resp = client.post(
1010
"/shipments/118/update-status",
1111
params={"token": ""},
@@ -24,3 +24,18 @@ def test_post(client):
2424
new_status = inner_db.session.scalar(select(Shipment.status).filter(Shipment.id == 118))
2525

2626
assert new_status == "New Status"
27+
28+
29+
def test_cancelled(client):
30+
"""Should treat "CREATED" as a pickup cancellation"""
31+
resp = client.post(
32+
"/shipments/118/update-status",
33+
params={"token": ""},
34+
json={"status": "CREATED", "origin_url": "https://fake.com", "pickup_confirmation_timestamp": 1},
35+
)
36+
37+
assert resp.status_code == 200
38+
39+
new_status = inner_db.session.scalar(select(Shipment.status).filter(Shipment.id == 118))
40+
41+
assert new_status == "Pickup Cancelled"

0 commit comments

Comments
 (0)