56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
def test_list_bookings_filters_by_vehicle(ops_client):
|
|
response = ops_client.get("/api/v1/bookings", params={"vehicle_ref": "MO-024"})
|
|
assert response.status_code == 200
|
|
bookings = response.json()
|
|
assert len(bookings) >= 1
|
|
assert all(b["vehicle_ref"] == "MO-024" for b in bookings)
|
|
|
|
|
|
def test_list_bookings_supports_bounded_search_pages(ops_client):
|
|
response = ops_client.get(
|
|
"/api/v1/bookings",
|
|
params={"query": "BK-", "page": 1, "page_size": 25},
|
|
)
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
assert body["page"] == 1
|
|
assert body["page_size"] == 25
|
|
assert body["total"] > 25
|
|
assert body["total_pages"] > 1
|
|
assert len(body["items"]) == 25
|
|
|
|
|
|
def test_create_booking_rejects_overlap_and_audits_valid_booking(ops_client):
|
|
conflict = ops_client.post(
|
|
"/api/v1/bookings",
|
|
json={
|
|
"customer_ref": "CUS-0001", "vehicle_ref": "MO-024",
|
|
"starts_at": "2026-08-10T10:00:00Z", "ends_at": "2026-08-10T12:00:00Z",
|
|
},
|
|
)
|
|
assert conflict.status_code == 409
|
|
created = ops_client.post(
|
|
"/api/v1/bookings",
|
|
json={
|
|
"customer_ref": "CUS-0001", "vehicle_ref": "MO-001",
|
|
"starts_at": "2026-09-01T10:00:00Z", "ends_at": "2026-09-02T12:00:00Z",
|
|
},
|
|
)
|
|
assert created.status_code == 201
|
|
body = created.json()
|
|
assert body["status"] == "reserved"
|
|
assert body["vehicle_ref"] == "MO-001"
|
|
|
|
|
|
def test_get_booking_detail(ops_client):
|
|
response = ops_client.get("/api/v1/bookings/BK-DEMO-RETURN")
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
assert body["status"] == "active"
|
|
assert body["vehicle_ref"] == "MO-024"
|
|
|
|
|
|
def test_get_booking_404_for_unknown_ref(ops_client):
|
|
response = ops_client.get("/api/v1/bookings/BK-UNKNOWN")
|
|
assert response.status_code == 404
|