Add service platform foundation
This commit is contained in:
75
tests/test_platform.py
Normal file
75
tests/test_platform.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from io import BytesIO
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_vin_validation_rejects_invalid_value(client, auth_headers) -> None:
|
||||
response = await client.post(
|
||||
"/api/my/vehicles",
|
||||
headers=auth_headers,
|
||||
json={"name": "Bad VIN", "vin": "IOQ123"},
|
||||
)
|
||||
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_service_visit_owner_confirmation_and_change_request(client, auth_headers) -> None:
|
||||
vehicle = (
|
||||
await client.post(
|
||||
"/api/my/vehicles",
|
||||
headers=auth_headers,
|
||||
json={"name": "Platform car", "license_plate": "12 가 3456", "license_plate_country": "KR"},
|
||||
)
|
||||
).json()
|
||||
center = (
|
||||
await client.post(
|
||||
"/api/service-centers",
|
||||
headers=auth_headers,
|
||||
json={"display_name": "Careful Service", "country": "KR", "city": "Seoul"},
|
||||
)
|
||||
).json()
|
||||
visit = (
|
||||
await client.post(
|
||||
f"/api/service-centers/{center['id']}/visits",
|
||||
headers=auth_headers,
|
||||
json={"vehicle_id": vehicle["id"], "visit_date": "2026-05-12", "odometer": 12345},
|
||||
)
|
||||
).json()
|
||||
|
||||
item_response = await client.post(
|
||||
f"/api/service-visits/{visit['id']}/work-items",
|
||||
headers=auth_headers,
|
||||
json={"work_type": "oil_change", "title": "Engine oil", "oil_viscosity": "5W-30", "price": 100},
|
||||
)
|
||||
complete_response = await client.post(f"/api/service-visits/{visit['id']}/complete", headers=auth_headers)
|
||||
confirm_response = await client.post(f"/api/service-visits/{visit['id']}/confirm", headers=auth_headers)
|
||||
change_request = (
|
||||
await client.post(
|
||||
f"/api/service-visits/{visit['id']}/vehicle-change-requests",
|
||||
headers=auth_headers,
|
||||
json={"vehicle_id": vehicle["id"], "field_name": "vin", "new_value": "KMHCT41BAHU123456"},
|
||||
)
|
||||
).json()
|
||||
approve_response = await client.post(
|
||||
f"/api/vehicle-change-requests/{change_request['id']}/approve",
|
||||
headers=auth_headers,
|
||||
)
|
||||
|
||||
assert item_response.status_code == 201
|
||||
assert complete_response.json()["status"] == "pending_owner_confirmation"
|
||||
assert confirm_response.json()["status"] == "confirmed"
|
||||
assert approve_response.json()["status"] == "approved"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ocr_candidates_do_not_write_vehicle_data(client, auth_headers) -> None:
|
||||
response = await client.post(
|
||||
"/api/ocr/vin",
|
||||
headers=auth_headers,
|
||||
files={"file": ("vin.txt", BytesIO(b"VIN KMHCT41BAHU123456"), "text/plain")},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["candidates"][0]["type"] == "vin"
|
||||
Reference in New Issue
Block a user