"""
Tests endpoint /health.
"""

from dataclasses import dataclass

from pricewatch.app.api.main import health_check


@dataclass
class FakeRedisConfig:
    url: str


@dataclass
class FakeDbConfig:
    url: str


@dataclass
class FakeAppConfig:
    db: FakeDbConfig
    redis: FakeRedisConfig
    api_token: str


def test_health_ok(monkeypatch):
    """Health retourne db/redis true."""
    config = FakeAppConfig(
        db=FakeDbConfig(url="sqlite:///:memory:"),
        redis=FakeRedisConfig(url="redis://localhost:6379/0"),
        api_token="secret",
    )
    monkeypatch.setattr("pricewatch.app.api.main.get_config", lambda: config)
    monkeypatch.setattr("pricewatch.app.api.main.check_db_connection", lambda cfg: True)
    monkeypatch.setattr("pricewatch.app.api.main.check_redis_connection", lambda url: True)

    result = health_check()
    assert result.db is True
    assert result.redis is True
