def test_user_profile_has_new_columns():
    from app.db import _conn
    with _conn() as conn:
        cols = {row["name"] for row in conn.execute("PRAGMA table_info(user_profile)")}
    assert "preferred_districts" in cols
    assert "min_match_score" in cols
    assert "notify_enabled" in cols


def test_announcements_has_district():
    from app.db import _conn
    with _conn() as conn:
        cols = {row["name"] for row in conn.execute("PRAGMA table_info(announcements)")}
    assert "district" in cols


def test_match_results_has_notified_at():
    from app.db import _conn
    with _conn() as conn:
        cols = {row["name"] for row in conn.execute("PRAGMA table_info(match_results)")}
    assert "notified_at" in cols


def test_district_index_exists():
    from app.db import _conn
    with _conn() as conn:
        idx = {row["name"] for row in conn.execute(
            "SELECT name FROM sqlite_master WHERE type='index'"
        )}
    assert "idx_ann_district" in idx


def test_profile_defaults():
    from app.db import upsert_profile, get_profile
    upsert_profile({"name": "테스트"})
    profile = get_profile()
    assert profile["preferred_districts"] == {}
    assert profile["min_match_score"] == 70
    assert profile["notify_enabled"] is True
