"""``extract_contacts`` behavior: harvest emails/phones/socials from raw HTML.""" from __future__ import annotations import pytest from app.utils.crawl import extract_contacts pytestmark = pytest.mark.unit def test_harvests_mailto_tel_and_socials() -> None: html = """
""" c = extract_contacts(html) assert c.emails == ["hello@acme.io"] # mailto query stripped assert c.phones == ["+1-555-0100"] assert c.socials == [ "https://www.linkedin.com/company/acme", "https://x.com/acme", "https://github.com/acme/repo", # fragment stripped ] # Same-site, non-social link is not a contact signal. assert "https://acme.io/about" not in c.socials def test_plaintext_email_without_mailto_is_found() -> None: html = "Reach us at hello@cochat.ai for support.
" assert extract_contacts(html).emails == ["hello@cochat.ai"] def test_filters_noise_emails_and_asset_false_positives() -> None: html = """
ops@sentry.io
x """ assert extract_contacts(html).emails == ["real@company.com"] def test_filters_template_placeholders() -> None: html = """youremail@business.com your.email@acme.io john-doe@acme.io
real gh template tw template real person """ c = extract_contacts(html) assert c.emails == ["hello@acme.io"] # your.email + john-doe normalized away assert c.socials == ["https://www.linkedin.com/in/jane-doe/"] def test_regional_social_hosts_are_harvested() -> None: """WhatsApp/Line/VK/Weibo etc. are the business contact channel outside the US.""" html = """ WhatsApp Line VK Weibo Xing """ assert len(extract_contacts(html).socials) == 5 def test_percent_encoded_hrefs_are_decoded() -> None: """Sites URL-encode tel/mailto hrefs (seen live: tel:+1%20408-629-1770).""" html = """ Call Email """ c = extract_contacts(html) assert c.phones == ["+1 408-629-1770"] assert "hello@acme.io" in c.emails def test_dedupes_case_insensitively_preserving_order() -> None: html = """ a b """ assert extract_contacts(html).emails == ["Hello@Acme.io"] def test_empty_or_unparseable_html_is_empty() -> None: assert extract_contacts("").is_empty assert extract_contacts(None).is_empty assert extract_contacts(" ").is_empty