- PDF generation with WeasyPrint: deviz and factura templates (A4, branding)
- GET /orders/{id}/pdf/deviz returns PDF with order lines and totals
- Client portal (public, no auth): GET /p/{token}, POST /p/{token}/accept|reject
- SMS service (SMSAPI.ro) - skips in dev when no token configured
- Invoice service: create from validated order, auto-number (F-YYYY-NNNN)
- GET /invoices/{id}/pdf returns factura PDF
- Order status_client field for client accept/reject tracking
- Alembic migration for status_client
- 19 passing tests (auth + sync + orders + pdf + portal + invoices)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
102 lines
2.8 KiB
Python
102 lines
2.8 KiB
Python
import uuid
|
|
from datetime import UTC, datetime
|
|
|
|
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from app.main import app
|
|
|
|
|
|
async def _setup_order_with_lines(client, auth_headers):
|
|
"""Create vehicle + order + lines, return order details."""
|
|
me = await client.get("/api/auth/me", headers=auth_headers)
|
|
tenant_id = me.json()["tenant_id"]
|
|
|
|
vid = str(uuid.uuid4())
|
|
now = datetime.now(UTC).isoformat()
|
|
await client.post(
|
|
"/api/sync/push",
|
|
headers=auth_headers,
|
|
json={
|
|
"operations": [
|
|
{
|
|
"table": "vehicles",
|
|
"id": vid,
|
|
"operation": "INSERT",
|
|
"data": {
|
|
"id": vid,
|
|
"tenant_id": tenant_id,
|
|
"nr_inmatriculare": "B99PDF",
|
|
"client_nume": "Ion Popescu",
|
|
"created_at": now,
|
|
"updated_at": now,
|
|
},
|
|
"timestamp": now,
|
|
}
|
|
]
|
|
},
|
|
)
|
|
|
|
r = await client.post(
|
|
"/api/orders",
|
|
headers=auth_headers,
|
|
json={"vehicle_id": vid},
|
|
)
|
|
order_id = r.json()["id"]
|
|
|
|
await client.post(
|
|
f"/api/orders/{order_id}/lines",
|
|
headers=auth_headers,
|
|
json={
|
|
"tip": "manopera",
|
|
"descriere": "Schimb ulei",
|
|
"ore": 1,
|
|
"pret_ora": 150,
|
|
},
|
|
)
|
|
|
|
# Get order to find token_client
|
|
r = await client.get(f"/api/orders/{order_id}", headers=auth_headers)
|
|
return r.json()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_portal_get_deviz(client, auth_headers):
|
|
order = await _setup_order_with_lines(client, auth_headers)
|
|
token = order["token_client"]
|
|
|
|
# Portal access is public (no auth headers)
|
|
r = await client.get(f"/api/p/{token}")
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert "order" in data
|
|
assert "tenant" in data
|
|
assert "lines" in data
|
|
assert data["order"]["nr_auto"] == "B99PDF"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_portal_accept(client, auth_headers):
|
|
order = await _setup_order_with_lines(client, auth_headers)
|
|
token = order["token_client"]
|
|
|
|
r = await client.post(f"/api/p/{token}/accept")
|
|
assert r.status_code == 200
|
|
assert r.json()["ok"] is True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_portal_reject(client, auth_headers):
|
|
order = await _setup_order_with_lines(client, auth_headers)
|
|
token = order["token_client"]
|
|
|
|
r = await client.post(f"/api/p/{token}/reject")
|
|
assert r.status_code == 200
|
|
assert r.json()["ok"] is True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_portal_invalid_token(client):
|
|
r = await client.get("/api/p/invalid-token")
|
|
assert r.status_code == 404
|