fix: resolve frontend/backend integration bugs

- Rename skincare route prefix /skin-snapshots → /skincare to match API client
- Add redirect_slashes=False to FastAPI app; change collection routes from "/" to ""
  to eliminate 307 redirects on POST/GET without trailing slash
- Fix redirect() inside try/catch in products/new and routines/new server actions
  (SvelteKit redirect() throws and was being caught as a 500 error)
- Eagerly load inventory and steps relationships via explicit SELECT + model_dump(mode="json"),
  working around SQLModel 0.0.37 not serializing Relationship fields in response_model
- Add field_validator for product_effect_profile to coerce DB-returned dict → ProductEffectProfile,
  eliminating Pydantic serializer warning
- Update all tests to use routes without trailing slash

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Piotr Oleszczyk 2026-02-26 21:53:17 +01:00
parent 8d4f9d1fc6
commit 9bf94a979c
11 changed files with 85 additions and 68 deletions

View file

@ -2,7 +2,7 @@ import uuid
def test_create_snapshot_minimal(client):
r = client.post("/skin-snapshots/", json={"snapshot_date": "2026-02-26"})
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
assert r.status_code == 201
data = r.json()
assert "id" in data
@ -12,7 +12,7 @@ def test_create_snapshot_minimal(client):
def test_create_snapshot_full(client):
r = client.post(
"/skin-snapshots/",
"/skincare",
json={
"snapshot_date": "2026-02-20",
"overall_state": "good",
@ -39,22 +39,22 @@ def test_create_snapshot_full(client):
def test_create_snapshot_invalid_state(client):
r = client.post(
"/skin-snapshots/",
"/skincare",
json={"snapshot_date": "2026-02-26", "overall_state": "stellar"},
)
assert r.status_code == 422
def test_list_snapshots_empty(client):
r = client.get("/skin-snapshots/")
r = client.get("/skincare")
assert r.status_code == 200
assert r.json() == []
def test_list_filter_date_range(client):
client.post("/skin-snapshots/", json={"snapshot_date": "2026-01-01"})
client.post("/skin-snapshots/", json={"snapshot_date": "2026-06-01"})
r = client.get("/skin-snapshots/?from_date=2026-05-01&to_date=2026-12-31")
client.post("/skincare", json={"snapshot_date": "2026-01-01"})
client.post("/skincare", json={"snapshot_date": "2026-06-01"})
r = client.get("/skincare?from_date=2026-05-01&to_date=2026-12-31")
assert r.status_code == 200
data = r.json()
assert len(data) == 1
@ -63,14 +63,14 @@ def test_list_filter_date_range(client):
def test_list_filter_overall_state(client):
client.post(
"/skin-snapshots/",
"/skincare",
json={"snapshot_date": "2026-02-10", "overall_state": "good"},
)
client.post(
"/skin-snapshots/",
"/skincare",
json={"snapshot_date": "2026-02-11", "overall_state": "poor"},
)
r = client.get("/skin-snapshots/?overall_state=poor")
r = client.get("/skincare?overall_state=poor")
assert r.status_code == 200
data = r.json()
assert len(data) == 1
@ -78,31 +78,31 @@ def test_list_filter_overall_state(client):
def test_get_snapshot(client):
r = client.post("/skin-snapshots/", json={"snapshot_date": "2026-02-26"})
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
sid = r.json()["id"]
r2 = client.get(f"/skin-snapshots/{sid}")
r2 = client.get(f"/skincare/{sid}")
assert r2.status_code == 200
assert r2.json()["id"] == sid
def test_get_snapshot_not_found(client):
r = client.get(f"/skin-snapshots/{uuid.uuid4()}")
r = client.get(f"/skincare/{uuid.uuid4()}")
assert r.status_code == 404
def test_update_snapshot_state(client):
r = client.post("/skin-snapshots/", json={"snapshot_date": "2026-02-26"})
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
sid = r.json()["id"]
r2 = client.patch(f"/skin-snapshots/{sid}", json={"overall_state": "excellent"})
r2 = client.patch(f"/skincare/{sid}", json={"overall_state": "excellent"})
assert r2.status_code == 200
assert r2.json()["overall_state"] == "excellent"
def test_update_snapshot_concerns(client):
r = client.post("/skin-snapshots/", json={"snapshot_date": "2026-02-26"})
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
sid = r.json()["id"]
r2 = client.patch(
f"/skin-snapshots/{sid}",
f"/skincare/{sid}",
json={"active_concerns": ["dehydration", "redness"]},
)
assert r2.status_code == 200
@ -113,20 +113,20 @@ def test_update_snapshot_concerns(client):
def test_update_snapshot_not_found(client):
r = client.patch(
f"/skin-snapshots/{uuid.uuid4()}", json={"overall_state": "good"}
f"/skincare/{uuid.uuid4()}", json={"overall_state": "good"}
)
assert r.status_code == 404
def test_delete_snapshot(client):
r = client.post("/skin-snapshots/", json={"snapshot_date": "2026-02-26"})
r = client.post("/skincare", json={"snapshot_date": "2026-02-26"})
sid = r.json()["id"]
r2 = client.delete(f"/skin-snapshots/{sid}")
r2 = client.delete(f"/skincare/{sid}")
assert r2.status_code == 204
r3 = client.get(f"/skin-snapshots/{sid}")
r3 = client.get(f"/skincare/{sid}")
assert r3.status_code == 404
def test_delete_snapshot_not_found(client):
r = client.delete(f"/skin-snapshots/{uuid.uuid4()}")
r = client.delete(f"/skincare/{uuid.uuid4()}")
assert r.status_code == 404