"""Tests para build_search_dorks."""

from build_search_dorks import build_search_dorks


def test_persona_genera_dorks_esperados():
    """El tipo persona produce frase exacta, linkedin, cv y filetypes."""
    out = build_search_dorks("Juan Perez", tipo="persona")
    assert '"Juan Perez"' in out
    assert '"Juan Perez" filetype:pdf' in out
    assert any("linkedin.com" in d for d in out)
    assert any("curriculum OR cv OR resume" in d for d in out)


def test_email_genera_dorks_esperados():
    """El tipo email busca en pastebin, breaches y filetypes."""
    out = build_search_dorks("bob@corp.com", tipo="email")
    assert '"bob@corp.com"' in out
    assert any("pastebin.com" in d for d in out)
    assert any("leak OR breach OR dump OR password" in d for d in out)
    assert '"bob@corp.com" filetype:csv' in out


def test_dominio_genera_site_dorks():
    """El tipo dominio produce site: y ficheros expuestos."""
    out = build_search_dorks("empresa.com", tipo="dominio")
    assert "site:empresa.com" in out
    assert "site:empresa.com filetype:xlsx" in out
    assert any("login OR admin OR dashboard" in d for d in out)
    assert "site:*.empresa.com" in out


def test_usuario_genera_redes_sociales():
    """El tipo usuario busca en github, reddit y por inurl."""
    out = build_search_dorks("jdoe", tipo="usuario")
    assert '"jdoe"' in out
    assert any("github.com" in d for d in out)
    assert any("reddit.com" in d for d in out)
    assert "inurl:jdoe" in out


def test_extra_domains_acota_con_site():
    """extra_domains añade dorks site:<dominio> con la frase exacta."""
    out = build_search_dorks(
        "Ana Ruiz", tipo="persona", extra_domains=["uni.edu", "gov.es"]
    )
    assert 'site:uni.edu "Ana Ruiz"' in out
    assert 'site:gov.es "Ana Ruiz"' in out


def test_tipo_desconocido_solo_frase_exacta():
    """Un tipo no reconocido devuelve solo la frase exacta (mas extras)."""
    out = build_search_dorks("algo", tipo="otracosa")
    assert out[0] == '"algo"'
    # Sin extras y tipo desconocido, solo la frase base.
    assert out == ['"algo"']
