80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
async def test_get_user_settings_returns_200(auth_client, user_settings):
|
|
response = await auth_client.get("/api/user/settings")
|
|
assert response.status_code == 200
|
|
|
|
|
|
async def test_get_user_settings_returns_correct_fields(auth_client, user_settings):
|
|
response = await auth_client.get("/api/user/settings")
|
|
body = response.json()
|
|
assert body["protein_goal"] == user_settings.protein_goal
|
|
assert body["carb_goal"] == user_settings.carb_goal
|
|
assert body["fat_goal"] == user_settings.fat_goal
|
|
assert body["fiber_goal"] == user_settings.fiber_goal
|
|
assert body["calories_goal"] == user_settings.calories_goal
|
|
assert body["id"] == user_settings.id
|
|
|
|
|
|
async def test_get_user_settings_not_found_returns_404(auth_client):
|
|
response = await auth_client.get("/api/user/settings")
|
|
assert response.status_code == 404
|
|
|
|
|
|
async def test_get_user_settings_without_auth_returns_401(client):
|
|
response = await client.get("/api/user/settings")
|
|
assert response.status_code == 401
|
|
|
|
|
|
async def test_update_user_settings_returns_200(auth_client, user_settings):
|
|
response = await auth_client.patch(
|
|
"/api/user/settings", json={"protein_goal": 180.0}
|
|
)
|
|
assert response.status_code == 200
|
|
|
|
|
|
async def test_update_user_settings_partial_update(auth_client, user_settings):
|
|
response = await auth_client.patch(
|
|
"/api/user/settings", json={"protein_goal": 180.0}
|
|
)
|
|
body = response.json()
|
|
assert body["protein_goal"] == 180.0
|
|
assert body["carb_goal"] == user_settings.carb_goal
|
|
assert body["fat_goal"] == user_settings.fat_goal
|
|
assert body["calories_goal"] == user_settings.calories_goal
|
|
|
|
|
|
async def test_update_user_settings_all_fields(auth_client, user_settings):
|
|
payload = {
|
|
"protein_goal": 120.0,
|
|
"carb_goal": 250.0,
|
|
"fat_goal": 60.0,
|
|
"fiber_goal": 25.0,
|
|
"calories_goal": 1800.0,
|
|
}
|
|
response = await auth_client.patch("/api/user/settings", json=payload)
|
|
body = response.json()
|
|
assert body["protein_goal"] == 120.0
|
|
assert body["carb_goal"] == 250.0
|
|
assert body["fat_goal"] == 60.0
|
|
assert body["fiber_goal"] == 25.0
|
|
assert body["calories_goal"] == 1800.0
|
|
|
|
|
|
async def test_update_user_settings_not_found_returns_404(auth_client):
|
|
response = await auth_client.patch(
|
|
"/api/user/settings", json={"protein_goal": 180.0}
|
|
)
|
|
assert response.status_code == 404
|
|
|
|
|
|
async def test_update_user_settings_negative_value_returns_422(
|
|
auth_client, user_settings
|
|
):
|
|
response = await auth_client.patch(
|
|
"/api/user/settings", json={"protein_goal": -10.0}
|
|
)
|
|
assert response.status_code == 422
|
|
|
|
|
|
async def test_update_user_settings_without_auth_returns_401(client):
|
|
response = await client.patch("/api/user/settings", json={"protein_goal": 180.0})
|
|
assert response.status_code == 401
|