40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
|
|
import pytest
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.anyio
|
||
|
|
async def test_dashboard_returns_seeded_summary(client):
|
||
|
|
resp = await client.get("/api/dashboard")
|
||
|
|
assert resp.status_code == 200
|
||
|
|
body = resp.json()
|
||
|
|
assert body["material_count"] == 1
|
||
|
|
assert body["finished_product_count"] == 2
|
||
|
|
assert body["supplier_count"] == 1
|
||
|
|
assert body["customer_count"] == 1
|
||
|
|
assert body["warehouse_count"] == 1
|
||
|
|
assert body["total_stock"] == 1000
|
||
|
|
assert float(body["total_value"]) == 10000.0
|
||
|
|
assert body["pending_purchase"] == 0
|
||
|
|
assert body["pending_sales"] == 0
|
||
|
|
assert body["low_stock_products"] == []
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.anyio
|
||
|
|
async def test_dashboard_low_stock_products_are_listed(client):
|
||
|
|
inventory = await client.get("/api/inventory")
|
||
|
|
assert inventory.status_code == 200
|
||
|
|
inv_id = next(row["id"] for row in inventory.json()["items"] if row["product_sku"] == "MAT-001")
|
||
|
|
|
||
|
|
updated = await client.put(
|
||
|
|
f"/api/inventory/{inv_id}",
|
||
|
|
json={"quantity": 0, "locked_quantity": 0},
|
||
|
|
)
|
||
|
|
assert updated.status_code == 200
|
||
|
|
|
||
|
|
resp = await client.get("/api/dashboard")
|
||
|
|
assert resp.status_code == 200
|
||
|
|
low_stock = resp.json()["low_stock_products"]
|
||
|
|
assert len(low_stock) == 1
|
||
|
|
assert low_stock[0]["sku"] == "MAT-001"
|
||
|
|
assert low_stock[0]["quantity"] == 0
|
||
|
|
assert low_stock[0]["min_stock"] == 0
|