"""Tests pour la commande CLI detect."""

import pytest
from typer.testing import CliRunner

from pricewatch.app.cli.main import app

runner = CliRunner()


class TestDetectCommand:
    """Tests pour la commande detect."""

    def test_detect_amazon_url(self):
        """Detect doit identifier une URL Amazon."""
        result = runner.invoke(app, ["detect", "https://www.amazon.fr/dp/B08N5WRWNW"])
        assert result.exit_code == 0
        assert "amazon" in result.stdout.lower()
        assert "B08N5WRWNW" in result.stdout

    def test_detect_cdiscount_url(self):
        """Detect doit identifier une URL Cdiscount."""
        result = runner.invoke(
            app,
            [
                "detect",
                "https://www.cdiscount.com/informatique/f-10709-tuf608umrv004.html",
            ],
        )
        assert result.exit_code == 0
        assert "cdiscount" in result.stdout.lower()

    def test_detect_unknown_url(self):
        """Detect doit echouer pour une URL inconnue."""
        result = runner.invoke(app, ["detect", "https://www.unknown-store.com/product"])
        assert result.exit_code == 1
        assert "aucun store" in result.stdout.lower()

    def test_detect_invalid_url(self):
        """Detect doit echouer pour une URL invalide."""
        result = runner.invoke(app, ["detect", "not-a-valid-url"])
        assert result.exit_code == 1
