def test_training_plan_and_record(client, auth_headers):
    child_id = client.post(
        "/api/children",
        headers=auth_headers,
        json={"name": "训练测试", "birthday": "2016-01-01", "gender": "male"},
    ).json()["data"]["id"]

    plan_resp = client.post(
        "/api/training/plans",
        headers=auth_headers,
        json={
            "childId": child_id,
            "goal": "改善头前伸",
            "cycleDays": 28,
        },
    )
    assert plan_resp.status_code == 201
    plan = plan_resp.json()["data"]
    plan_id = plan["id"]
    assert plan["status"] == "active"
    assert plan["detail"]["cycleDays"] == 28

    detail = client.get(f"/api/training/plans/{plan_id}", headers=auth_headers)
    assert detail.status_code == 200

    record_resp = client.post(
        f"/api/training/plans/{plan_id}/records",
        headers=auth_headers,
        json={
            "exerciseId": 1,
            "completed": True,
            "score": 81,
            "durationSeconds": 272,
        },
    )
    assert record_resp.status_code == 201
    assert record_resp.json()["data"]["score"] == 81

    updated = client.get(f"/api/training/plans/{plan_id}", headers=auth_headers).json()["data"]
    assert updated["detail"]["completedDays"] == 1


def test_admin_dashboard(client, auth_headers):
    client.post(
        "/api/children",
        headers=auth_headers,
        json={"name": "看板测试", "birthday": "2015-06-01", "gender": "female"},
    )
    dash = client.get("/api/admin/dashboard", headers=auth_headers)
    assert dash.status_code == 200
    data = dash.json()["data"]
    assert "newChildren" in data
    assert "activePlans" in data
    assert data["newChildren"] >= 1
