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..4120290 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -1,6 +1,7 @@
"""Shipping with Tern, our carrier. Use shop.tern.call for requests; shop.settings has the warehouse postcode."""
from datetime import date
+from shop import tern
from shop.cart import Cart
from shop.orders import Order
@@ -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 shipments listing 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..b987b0b
--- /dev/null
+++ b/tests/test_shipping.py
@@ -0,0 +1,25 @@
+from datetime import date
+
+import pytest
+
+from shop import shipping
+
+
+def test_shipments_since_follows_cursors(monkeypatch):
+ pages = {None: {"shipments": [{"id": "a"}], "next_cursor": "c1"}, "c1": {"shipments": [{"id": "b"}]}}
+ seen = []
+
+ def fake_call(method, path, params=None, **kw):
+ seen.append(params)
+ return 200, pages[params.get("cursor")]
+
+ monkeypatch.setattr(shipping.tern, "call", fake_call)
+ assert shipping.shipments_since(date(2026, 11, 1)) == [{"id": "a"}, {"id": "b"}]
+ assert seen[0] == {"created_since": "2026-11-01"}
+ assert seen[1] == {"created_since": "2026-11-01", "cursor": "c1"}
+
+
+def test_shipments_since_raises_on_error(monkeypatch):
+ monkeypatch.setattr(shipping.tern, "call", lambda *a, **k: (500, {}))
+ with pytest.raises(RuntimeError):
+ shipping.shipments_since(date(2026, 11, 1))