bugfix: Invoice details
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -25,7 +25,16 @@ class Client:
|
||||
|
||||
def bill_pdf(self, msisdn, invoice_id, customer_id, **kwargs):
|
||||
self.pdf_calls += 1
|
||||
return {"119": {"SVA Detalhe Total": [{"desc": "Tamboro"}]}}
|
||||
return {
|
||||
"status": "SUCCESS",
|
||||
"parsed_content": {
|
||||
"total_geral": 191.97,
|
||||
"Fatura Resumo": [
|
||||
{"desc": "Período", "period": "01/04/2026 a 30/04/2026"},
|
||||
{"desc": "Emissão", "emissao": "01/04/2026"},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -196,3 +205,73 @@ async def test_invoice_context_cache_hit_expoe_cache_age_sem_republicar_eventos(
|
||||
assert cached.metadata["cache_hit"] is True
|
||||
assert cached.metadata["cache_age_ms"] >= 0
|
||||
assert cached.business_events == []
|
||||
|
||||
|
||||
def test_extract_invoice_summary_context_restaura_semantica_do_original():
|
||||
from app.domain.contas.invoice_context import extract_invoice_summary_context
|
||||
|
||||
result = extract_invoice_summary_context({
|
||||
"parsed_content": {
|
||||
"total_geral": 191.97,
|
||||
"Fatura Resumo": [
|
||||
{"desc": "Período", "period": "01/04/2026 a 30/04/2026"},
|
||||
{"desc": "Emissão", "emissao": "01/04/2026"},
|
||||
],
|
||||
}
|
||||
})
|
||||
assert result == {
|
||||
"invoice_amount": "191.97",
|
||||
"invoice_amount_open": "191.97",
|
||||
"invoice_period": "01/04/2026 a 30/04/2026",
|
||||
"invoice_emissao": "01/04/2026",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invoice_context_detail_expoe_invoice_amount_semantico():
|
||||
client = Client()
|
||||
svc = InvoiceContextService(client, InMemoryCache(), ttl_seconds=60) # type: ignore[arg-type]
|
||||
ctx = await svc.get(session_id="s1", msisdn="119", include_detail=True)
|
||||
assert ctx.invoice_amount == "191.97"
|
||||
assert ctx.invoice_amount_open == "191.97"
|
||||
assert ctx.invoice_period == "01/04/2026 a 30/04/2026"
|
||||
assert ctx.invoice_emissao == "01/04/2026"
|
||||
assert ctx.as_dict()["invoice_amount"] == "191.97"
|
||||
|
||||
|
||||
def test_consultar_faturas_reusa_prefetch_e_publica_valor_sem_reconsultar_backend():
|
||||
from app.domain.contas.service import ContasDomainService
|
||||
|
||||
class C(Client):
|
||||
def consultar_faturas(self, msisdn):
|
||||
raise AssertionError("nao deveria consultar novamente")
|
||||
|
||||
svc = ContasDomainService(client=C()) # type: ignore[arg-type]
|
||||
result = svc.consultar_faturas(
|
||||
msisdn="119",
|
||||
complete_invoices_payload={"paymentItems": [{"invoiceId": "I1"}]},
|
||||
invoice_id="I1",
|
||||
customer_id="C1",
|
||||
invoice_amount="191.97",
|
||||
invoice_amount_open="191.97",
|
||||
)
|
||||
assert result["invoice_amount"] == "191.97"
|
||||
assert result["invoice_amount_open"] == "191.97"
|
||||
assert result["invoice_id"] == "I1"
|
||||
assert result["customer_id"] == "C1"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_consultar_faturas_enriquece_com_detail_e_valor(monkeypatch):
|
||||
from contas_mcp.servers.contas_mcp_server import main
|
||||
|
||||
client = Client()
|
||||
context_service = InvoiceContextService(client, InMemoryCache(), ttl_seconds=60) # type: ignore[arg-type]
|
||||
monkeypatch.setattr(main, "get_invoice_context_service", lambda: context_service)
|
||||
|
||||
args = {"msisdn": "119", "session_id": "s1", "message_id": "m1"}
|
||||
await main._enrich_invoice_context("consultar_faturas", args)
|
||||
|
||||
assert client.pdf_calls == 1
|
||||
assert args["invoice_amount"] == "191.97"
|
||||
assert args["invoice_amount_open"] == "191.97"
|
||||
assert args["complete_invoices_payload"]["paymentItems"][0]["invoiceId"] == "I1"
|
||||
|
||||
Reference in New Issue
Block a user