async def test_health(client):
    resp = await client.get("/health")
    assert resp.status_code == 200
    assert resp.json()["status"] == "ok"


async def test_items_crud(client):
    # create
    resp = await client.post("/api/v1/items", json={"name": "demo", "description": "d"})
    assert resp.status_code == 201
    item = resp.json()
    assert item["name"] == "demo"
    item_id = item["id"]

    # get
    resp = await client.get(f"/api/v1/items/{item_id}")
    assert resp.status_code == 200

    # list
    resp = await client.get("/api/v1/items")
    assert resp.status_code == 200
    assert resp.json()["total"] >= 1

    # update
    resp = await client.patch(f"/api/v1/items/{item_id}", json={"name": "demo2"})
    assert resp.status_code == 200
    assert resp.json()["name"] == "demo2"

    # delete
    resp = await client.delete(f"/api/v1/items/{item_id}")
    assert resp.status_code == 204
    resp = await client.get(f"/api/v1/items/{item_id}")
    assert resp.status_code == 404
