from fmatch.saas.operators.extract_domain_root import extract_domain_root


def test_root():
    assert (
        extract_domain_root("https://www.blog.acme.com/path")["value"]
        == "acme.com"
    )


def test_email_extraction():
    """Test that emails are properly handled by extracting domain after @."""
    assert extract_domain_root("candice_aarons@hotmail.com")["value"] == "hotmail.com"
    assert extract_domain_root("george.abad@lmhosp.org")["value"] == "lmhosp.org"
    assert extract_domain_root("barb.abdalla@nationwidechildrens.org")["value"] == "nationwidechildrens.org"
    assert extract_domain_root("user@sub.example.co.uk")["value"] == "example.co.uk"
    assert extract_domain_root("test@gmail.com")["value"] == "gmail.com"


def test_empty_and_invalid():
    """Test empty and invalid inputs."""
    assert extract_domain_root("")["value"] == ""
    assert extract_domain_root(None)["value"] == ""
    assert extract_domain_root("   ")["value"] == ""

