Every shipment since a date, all pages (needs from the docs: D4 paging)
diff --git a/shop/shipping.py b/shop/shipping.py
index 5c4358a..a1222df 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -3,6 +3,7 @@ from datetime import date
from shop.cart import Cart
from shop.orders import Order
+from shop import tern
def quote_at_checkout(cart: Cart, postcode: str) -> int:
@@ -23,7 +24,19 @@ def book(order: Order, service: str) -> str:
def shipments_since(day: date) -> list[dict]:
"""Every Tern shipment created on or after day, as Tern describes them."""
- raise NotImplementedError
+ shipments = []
+ cursor = None
+ while True:
+ params = {"created_since": day.isoformat()}
+ if cursor:
+ params["cursor"] = cursor
+ status, body = tern.call("GET", "/v2/shipments", params=params)
+ if status != 200:
+ raise RuntimeError(f"Tern shipment list failed: {status} {body}")
+ shipments.extend(body["shipments"])
+ cursor = body.get("next_cursor")
+ if not cursor:
+ return shipments
def order_status(shipment_id: str) -> str:
diff --git a/tests/test_shipping.py b/tests/test_shipping.py
new file mode 100644
index 0000000..cb6a0b3
--- /dev/null
+++ b/tests/test_shipping.py
@@ -0,0 +1,19 @@
+from datetime import date
+
+from shop import shipping, tern
+
+
+def test_shipments_since_follows_pages(monkeypatch):
+ pages = {None: ([{"id": "a", "created_at": "2026-10-20"}], "c1"),
+ "c1": ([{"id": "b", "created_at": "2026-10-21"}], None)}
+ seen = []
+
+ def fake_call(method, path, params=None, **kw):
+ seen.append(params)
+ items, nxt = pages[params.get("cursor")]
+ return 200, {"shipments": items, "next_cursor": nxt}
+
+ monkeypatch.setattr(tern, "call", fake_call)
+ result = shipping.shipments_since(date(2026, 10, 20))
+ assert [s["id"] for s in result] == ["a", "b"]
+ assert all(p["created_since"] == "2026-10-20" for p in seen)