feat: add step thumbs feedback and /ratings alias routes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -87,3 +87,129 @@ async def test_rate_incomplete_session(client: AsyncClient, auth_headers: dict,
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
# --- Step Feedback Tests ---
|
||||
|
||||
@pytest.fixture
|
||||
async def test_step(client: AsyncClient, auth_headers: dict):
|
||||
"""Create a step in the step library."""
|
||||
response = await client.post(
|
||||
"/api/v1/steps",
|
||||
json={
|
||||
"title": "Test Step",
|
||||
"step_type": "action",
|
||||
"content": {
|
||||
"instructions": "Run the diagnostic command",
|
||||
"commands": [{"label": "Echo test", "command": "echo hello"}]
|
||||
},
|
||||
},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 201, f"Failed to create step: {response.text}"
|
||||
return response.json()
|
||||
|
||||
|
||||
async def test_step_feedback_thumbs_up(client: AsyncClient, auth_headers: dict, test_step: dict, test_session: dict):
|
||||
"""Submit thumbs-up feedback for a step."""
|
||||
response = await client.post(
|
||||
f"/api/v1/steps/{test_step['id']}/feedback",
|
||||
json={"session_id": test_session["id"], "was_helpful": True},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 201
|
||||
data = response.json()
|
||||
assert data["was_helpful"] is True
|
||||
assert data["status"] == "created"
|
||||
|
||||
|
||||
async def test_step_feedback_thumbs_down(client: AsyncClient, auth_headers: dict, test_step: dict, test_session: dict):
|
||||
"""Submit thumbs-down feedback for a step."""
|
||||
response = await client.post(
|
||||
f"/api/v1/steps/{test_step['id']}/feedback",
|
||||
json={"session_id": test_session["id"], "was_helpful": False},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 201
|
||||
data = response.json()
|
||||
assert data["was_helpful"] is False
|
||||
assert data["status"] == "created"
|
||||
|
||||
|
||||
async def test_step_feedback_toggle(client: AsyncClient, auth_headers: dict, test_step: dict, test_session: dict):
|
||||
"""Submitting again for same step+session updates the rating."""
|
||||
await client.post(
|
||||
f"/api/v1/steps/{test_step['id']}/feedback",
|
||||
json={"session_id": test_session["id"], "was_helpful": True},
|
||||
headers=auth_headers,
|
||||
)
|
||||
response = await client.post(
|
||||
f"/api/v1/steps/{test_step['id']}/feedback",
|
||||
json={"session_id": test_session["id"], "was_helpful": False},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 201
|
||||
data = response.json()
|
||||
assert data["was_helpful"] is False
|
||||
assert data["status"] == "updated"
|
||||
|
||||
|
||||
async def test_step_feedback_not_found(client: AsyncClient, auth_headers: dict, test_session: dict):
|
||||
"""Feedback on non-existent step returns 404."""
|
||||
import uuid
|
||||
fake_id = str(uuid.uuid4())
|
||||
response = await client.post(
|
||||
f"/api/v1/steps/{fake_id}/feedback",
|
||||
json={"session_id": test_session["id"], "was_helpful": True},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
# --- /ratings Alias Route Tests ---
|
||||
|
||||
async def test_ratings_alias_post(client: AsyncClient, auth_headers: dict, test_step: dict):
|
||||
"""POST /steps/{id}/ratings works as alias for /rate."""
|
||||
response = await client.post(
|
||||
f"/api/v1/steps/{test_step['id']}/ratings",
|
||||
json={"rating": 4, "was_helpful": True},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 201
|
||||
data = response.json()
|
||||
assert data["rating"] == 4
|
||||
|
||||
|
||||
async def test_ratings_alias_put(client: AsyncClient, auth_headers: dict, test_step: dict):
|
||||
"""PUT /steps/{id}/ratings works as alias for /rate."""
|
||||
# First create a rating
|
||||
await client.post(
|
||||
f"/api/v1/steps/{test_step['id']}/rate",
|
||||
json={"rating": 3, "was_helpful": True},
|
||||
headers=auth_headers,
|
||||
)
|
||||
# Update via alias
|
||||
response = await client.put(
|
||||
f"/api/v1/steps/{test_step['id']}/ratings",
|
||||
json={"rating": 5},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["rating"] == 5
|
||||
|
||||
|
||||
async def test_ratings_alias_delete(client: AsyncClient, auth_headers: dict, test_step: dict):
|
||||
"""DELETE /steps/{id}/ratings works as alias for /rate."""
|
||||
# First create a rating
|
||||
await client.post(
|
||||
f"/api/v1/steps/{test_step['id']}/rate",
|
||||
json={"rating": 4, "was_helpful": True},
|
||||
headers=auth_headers,
|
||||
)
|
||||
# Delete via alias
|
||||
response = await client.delete(
|
||||
f"/api/v1/steps/{test_step['id']}/ratings",
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert response.status_code == 204
|
||||
|
||||
Reference in New Issue
Block a user