"""Smoke test for Form 499 Initial Registration handler. Op 14: confirms the new-filer registration handler can be instantiated, the right guards fire (missing FRN, already-has-filer-id, auto-filing admin review path), and the SERVICE_HANDLERS registry entry maps to this class. Does NOT hit USAC — we mock `undetected_browser` out so the test stays hermetic. Run: python -m scripts.tests.test_form_499_initial_smoke """ from __future__ import annotations import asyncio import sys from pathlib import Path # Make the repo importable. REPO_ROOT = Path(__file__).resolve().parents[2] if str(REPO_ROOT) not in sys.path: sys.path.insert(0, str(REPO_ROOT)) def _make_entity(**kwargs) -> dict: base = { "id": 1, "legal_name": "ACME Telecom LLC", "frn": "0123456789", "ein": "12-3456789", "filer_id_499": None, "ceo_name": "Jane Doe", "ceo_title": "CEO", "contact_name": "Jane Doe", "contact_email": "ops@acme.example", "contact_phone": "+12125551212", "address_street": "100 Main St", "address_city": "Austin", "address_state": "TX", "address_zip": "78701", "jurisdiction": "FCC", "line_105_primary": "clec", "line_105_categories": [{"id": "clec", "infra_type": "facilities"}], } base.update(kwargs) return base def _make_order(name: str, entity: dict) -> dict: return { "name": name, "order_number": name, "service_slug": "fcc-499-initial", "service_name": "Form 499 Initial Registration", "entity": entity, "auto_file_disabled": False, } async def _run_case(handler, label: str, order: dict) -> tuple[bool, str]: try: # We want the handler to reach its guard paths without actually # launching a browser. We monkeypatch the submit method so any # case that bypasses the guards returns cleanly instead of # timing out against USAC. if hasattr(handler, "_submit_to_usac_efile"): async def _noop(*a, **k): return ("812999999", "/tmp/confirm.pdf") handler._submit_to_usac_efile = _noop # type: ignore[assignment] # Stub out ToDo creation so we don't hit ERPNext. todo_calls: list[tuple[str, str]] = [] def _stub_todo(order_number, description): todo_calls.append((order_number, description[:80])) handler._create_admin_todo = _stub_todo # type: ignore[assignment] result = await handler.process(order) return True, f"process returned {result!r}; todos={todo_calls}" except Exception as exc: return False, f"raised {exc!r}" async def amain() -> int: from scripts.workers.services.form_499_initial import Form499InitialHandler from scripts.workers.services import SERVICE_HANDLERS print("=" * 72) print("Form 499 Initial smoke test") print("=" * 72) # Registry check. cls = SERVICE_HANDLERS.get("fcc-499-initial") if cls is Form499InitialHandler: print(" SERVICE_HANDLERS['fcc-499-initial'] → Form499InitialHandler OK") registry_ok = True else: print(f" SERVICE_HANDLERS mismatch: got {cls!r} FAIL") registry_ok = False cases = [ ( "missing FRN → ToDo + return []", _make_order("CO-SMOKE-1", _make_entity(frn=None)), ), ( "already has filer_id → short-circuit skip", _make_order("CO-SMOKE-2", _make_entity(filer_id_499="812123456")), ), ( "happy path: auto-filing allowed → submit stub", _make_order("CO-SMOKE-3", _make_entity()), ), ] results: list[tuple[bool, str, str]] = [] for label, order in cases: handler = Form499InitialHandler() ok, detail = await _run_case(handler, label, order) results.append((ok, label, detail)) print("\nHandler cases:") for ok, label, detail in results: status = "OK" if ok else "FAIL" print(f" [{status}] {label}") print(f" {detail}") all_ok = registry_ok and all(r[0] for r in results) print() print("=" * 72) print("PASS" if all_ok else "FAIL") print("=" * 72) return 0 if all_ok else 1 def main() -> int: return asyncio.run(amain()) if __name__ == "__main__": sys.exit(main())