from fastapi.testclient import TestClient


def test_profile_update_accepts_new_fields():
    from app.main import app
    body = {
        "name": "테스트",
        "preferred_districts": {
            "S": ["강남구", "서초구"],
            "A": ["송파구"],
            "B": [],
            "C": [],
            "D": [],
        },
        "min_match_score": 75,
        "notify_enabled": True,
    }
    with TestClient(app) as client:
        resp = client.put("/api/realestate/profile", json=body)
    assert resp.status_code == 200
    data = resp.json()
    assert data["preferred_districts"]["S"] == ["강남구", "서초구"]
    assert data["min_match_score"] == 75
    assert data["notify_enabled"] is True


def test_profile_get_returns_defaults_for_new_fields():
    from app.main import app
    from app.db import upsert_profile
    upsert_profile({"name": "기본"})

    with TestClient(app) as client:
        resp = client.get("/api/realestate/profile")
    assert resp.status_code == 200
    data = resp.json()
    assert data["preferred_districts"] == {}
    assert data["min_match_score"] == 70
    assert data["notify_enabled"] is True
