"""D6: GET /v1/catalog/metrics.""" from tests import factories async def headers() -> dict: return (await factories.make_account())["headers"] async def test_hitting_catalog(client): response = await client.get("/v1/catalog/metrics?mode=h", headers=await headers()) assert response.status_code == 200 body = response.json() assert body["groups"] == [ {"group": "balance_load", "display_name": "Balance and Load"}, {"group": "stride", "display_name": "Stride"}, {"group": "power_move", "display_name": "Power Move"}, {"group": "contact_follow_through", "display_name": "Contact and Follow-Through"}, ] assert [m["metric_id"] for m in body["metrics"]] == [ "hip_shoulder_separation_at_foot_down", "stride_relative_length", "hip_shoulder_separation_at_contact"] assert body["metrics"][1] == {"metric_id": "stride_relative_length", "display_name": "Stride Length", "group": "stride", "unit": "cm", "what_it_means": "How far your front foot steps forward."} drill = next(d for d in body["drills"] if d["drill_id"] == "hit_13") assert drill == {"drill_id": "hit_13", "name": "Front Shoulder In Tee", "how": "Set the tee on the outer half. Keep your front shoulder pointed at the pitcher until your " "hips have turned, then swing.", "cue": "Shoulder in.", "reps": "3x8"} assert all(d["drill_id"].startswith("hit_") for d in body["drills"]) async def test_default_mode_is_hitting(client): response = await client.get("/v1/catalog/metrics", headers=await headers()) assert response.status_code == 200 and len(response.json()["metrics"]) == 3 async def test_pitching_catalog(client): response = await client.get("/v1/catalog/metrics?mode=p", headers=await headers()) assert response.status_code == 200 body = response.json() assert body["metrics"] == [] and body["groups"] == [] assert body["drills"] and all(d["drill_id"].startswith("pit_") for d in body["drills"]) async def test_invalid_mode(client): response = await client.get("/v1/catalog/metrics?mode=x", headers=await headers()) assert response.status_code == 400 assert response.json()["error"]["code"] == "VALIDATION" async def test_unauthenticated(client): response = await client.get("/v1/catalog/metrics?mode=h") assert response.status_code == 401 assert response.json()["error"]["code"] == "UNAUTHENTICATED"