"""Integration test: verify all tables exist after migration."""

import pytest
from sqlalchemy import text

EXPECTED_TABLES = [
    "issuer_master",
    "symbol_master",
    "job_runs",
    "documents",
    "document_exhibits",
    "exhibit_cache",
    "events",
    "event_parses",
    "macro_series",
    "macro_observations",
    "short_sale_daily",
    "feature_snapshots",
    "order_plans",
    "sync_checkpoints",
]


@pytest.mark.integration
@pytest.mark.asyncio
async def test_all_tables_exist(db_session):
    """All expected tables should exist after migration."""
    result = await db_session.execute(
        text("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
    )
    existing = {row[0] for row in result}
    for table in EXPECTED_TABLES:
        assert table in existing, f"Table {table!r} missing after migration"


@pytest.mark.integration
@pytest.mark.asyncio
async def test_db_health(db_session):
    from libs.db.helpers import health_check

    assert await health_check(db_session) is True
