59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
from pathlib import Path
|
|
from inspect import getsource
|
|
|
|
from app.admin_ui.pages.opportunities import (
|
|
_opportunity_board_column_for_opportunity,
|
|
_opportunity_card_next_action,
|
|
)
|
|
|
|
|
|
def opportunity(**overrides):
|
|
item = {
|
|
"id": "opp-1",
|
|
"stage": "INVOICE_REQUESTED",
|
|
"status": "open",
|
|
"lifecycle_state": "active",
|
|
"pending_task_count": 2,
|
|
"pending_primary_action_code": "SEND_INVOICE",
|
|
"pending_primary_action": "Enviar fatura ao cliente",
|
|
"clientflow_next_action": {
|
|
"action_code": "RECONCILE_DOCUMENTS",
|
|
"label": "Associar orçamento enviado",
|
|
"description": "Documento enviado ainda não associado.",
|
|
},
|
|
"metadata": {},
|
|
}
|
|
item.update(overrides)
|
|
return item
|
|
|
|
|
|
def test_board_primary_action_uses_structured_decision_not_stale_pending_task():
|
|
assert _opportunity_card_next_action(opportunity()) == "Associar orçamento enviado"
|
|
|
|
|
|
def test_board_column_uses_structured_decision_not_stale_financial_task():
|
|
assert _opportunity_board_column_for_opportunity(opportunity()) != "payment"
|
|
|
|
|
|
def test_detail_does_not_replace_structured_decision_with_arbitrary_pending_task():
|
|
source = Path("app/admin_ui/pages/opportunities.py").read_text(encoding="utf-8")
|
|
detail = source[source.index("async def opportunity_detail_page"):]
|
|
assert "elif not lifecycle_override and next_task:" not in detail
|
|
|
|
|
|
def test_explicit_scheduled_call_remains_a_valid_primary_override():
|
|
opp = opportunity(
|
|
lifecycle_state="active",
|
|
pending_follow_up_action_code="CALL_CUSTOMER",
|
|
pending_follow_up_action="Ligar ao cliente",
|
|
pending_follow_up_due_at="2099-08-21T09:00:00+00:00",
|
|
)
|
|
assert _opportunity_card_next_action(opp).startswith("Ligar ao cliente em")
|
|
|
|
|
|
def test_opportunity_list_read_path_does_not_attempt_schema_writes():
|
|
from app.opportunity_service import list_opportunities
|
|
|
|
source = getsource(list_opportunities)
|
|
assert "ensure_opportunity_schema()" not in source
|