48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from backend.main import app
|
|
|
|
def test_list_chores():
|
|
with TestClient(app) as client:
|
|
auth_res = client.post("/api/auth/demo-login", json={"email": "admin@choreus.app"})
|
|
token = auth_res.json()["access_token"]
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
|
|
response = client.get("/api/chores/types", headers=headers)
|
|
assert response.status_code == 200
|
|
chores = response.json()
|
|
assert len(chores) >= 1
|
|
assert "title" in chores[0]
|
|
|
|
def test_create_and_complete_chore():
|
|
with TestClient(app) as client:
|
|
admin_res = client.post("/api/auth/demo-login", json={"email": "admin@choreus.app"})
|
|
admin_token = admin_res.json()["access_token"]
|
|
admin_headers = {"Authorization": f"Bearer {admin_token}"}
|
|
|
|
# Create chore
|
|
chore_res = client.post("/api/chores/types", headers=admin_headers, json={
|
|
"title": "Clean Garage",
|
|
"description": "Organize tools and sweep floor",
|
|
"star_reward": 5,
|
|
"recurrence": "weekly",
|
|
"icon": "Wrench"
|
|
})
|
|
assert chore_res.status_code == 200
|
|
chore_data = chore_res.json()
|
|
chore_id = chore_data["id"]
|
|
|
|
# Complete chore as user
|
|
user_res = client.post("/api/auth/demo-login", json={"email": "leo@choreus.app"})
|
|
user_token = user_res.json()["access_token"]
|
|
user_headers = {"Authorization": f"Bearer {user_token}"}
|
|
|
|
comp_res = client.post("/api/chores/complete", headers=user_headers, json={
|
|
"chore_type_id": chore_id,
|
|
"notes": "Done with garage!"
|
|
})
|
|
assert comp_res.status_code == 200
|
|
comp_data = comp_res.json()
|
|
assert comp_data["stars_earned"] == 5
|
|
assert comp_data["chore_title"] == "Clean Garage"
|