HR-ATS-Portal/backend/tests/test_inbox_phone.py

48 lines
1.5 KiB
Python

"""employment_agent.plugins parse_phone — stacked clamp_phone + prefer_extracted_phone."""
from __future__ import annotations
from employment_agent.plugins import parse_phone, prefer_full_phone
def _digits(value):
return "".join(c for c in (value or "") if c.isdigit())
def test_pk_local_keeps_all_eleven_digits():
fields=parse_phone({},"Ali 0321-5551234 Engineer")
assert _digits(fields["phone"])=="03215551234"
def test_plus_ninety_two_keeps_last_group():
fields=parse_phone({},"Phone: +92 333 123 4567")
digits=_digits(fields["phone"])
assert digits.endswith("1234567")
assert len(digits)>=12
def test_pdf_wrapped_last_three_digits_are_kept():
fields=parse_phone({},"Mobile: 0300-1234\n567")
assert _digits(fields["phone"])=="03001234567"
def test_does_not_swallow_a_year_after_the_number():
fields=parse_phone({},"0321-5551234 2018 — 2024 Engineer")
assert _digits(fields["phone"])=="03215551234"
def test_four_three_four_grouping_is_complete():
fields=parse_phone({},"Cell: 0301 234 5678")
assert _digits(fields["phone"])=="03012345678"
def test_form_phone_without_resume_is_kept_when_complete():
fields=parse_phone({"phone":"0321-5551234"},"")
assert _digits(fields["phone"])=="03215551234"
def test_prefer_full_phone_picks_the_longer_complete_number():
assert prefer_full_phone("0300-1234","0300-1234567")=="0300-1234567"
assert prefer_full_phone(None,"0321-5551234")=="0321-5551234"
assert prefer_full_phone("0300-123",None) is None