feat(5.7): raspuns API onest la blocaje + mapare inline din detaliu
Raportat din client VFP: POST /v1/prezentari raspundea submission_id+status
fara motiv pe randuri blocate (erori se popula doar pe on_unmapped_error=True),
deci un needs_data/needs_mapping parea succes.
API (aditiv): SubmissionResult += nemapate + motiv. create_prezentari
populeaza erori (validare continut, 3 niveluri) / nemapate (coduri fara
mapare, COD_NEMAPAT) / motiv (rezumat uman) pe TOATE caile non-queued —
enqueue, respins (on_unmapped_error=True) si reactivare dedup peste error,
prin helperele _rezultat_enqueue / _rezultat_respins / _motiv_clasificare.
on_unmapped_error=True pastreaza erori=COD_NEMAPAT (compat clienti vechi).
Web: mapare inline in panoul de detaliu trimitere — ruta
POST /trimitere/{id}/mapeaza (reuse save_mapping + reresolve_account, scoped
sesiune + CSRF, re-rezolva pe batch_id-ul randului), helper
_nemapate_pentru_submission + context in _detaliu_ctx, sectiune in
_trimitere_detaliu.html (selector cod RAR cu sugestie fuzzy preselectata).
Apare doar pe operatii nemapate reale (nu pe auto_send=0).
/code-review high: reparat raspuns neonest la reactivare + dublu
load_nomenclator in _detaliu_ctx.
Teste: pytest -q 765 passed. Backend trimitere (worker/masina stari/
idempotenta) si schema NEATINSE. PRD: docs/prd/prd-5.7-*.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,61 @@ def test_idempotenta_dedup(client):
|
||||
assert res2["deduped"] is True
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# PRD 5.7 — raspuns onest: erori/nemapate/motiv pe randuri blocate #
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
def test_needs_data_intoarce_erori(client):
|
||||
"""Data in viitor -> needs_data + erori 3 niveluri (DATA_VIITOR) + motiv negol."""
|
||||
r = client.post("/v1/prezentari", json=_body(data_prestatie="2099-01-01"))
|
||||
res = r.json()["results"][0]
|
||||
assert res["status"] == "needs_data"
|
||||
assert res["nemapate"] == []
|
||||
coduri = [e["cod"] for e in res["erori"]]
|
||||
assert "DATA_VIITOR" in coduri
|
||||
assert res["erori"][0]["field"] == "data_prestatie"
|
||||
assert res["motiv"] # rezumat uman negol
|
||||
|
||||
|
||||
def test_vin_invalid_intoarce_erori_pe_camp(client):
|
||||
"""VIN cu O/I/Q -> erori cu field='vin'."""
|
||||
r = client.post("/v1/prezentari", json=_body(vin="WVWZZZ1OZIQ45678"))
|
||||
res = r.json()["results"][0]
|
||||
assert res["status"] == "needs_data"
|
||||
fields = [e["field"] for e in res["erori"]]
|
||||
assert "vin" in fields
|
||||
|
||||
|
||||
def test_needs_mapping_intoarce_nemapate(client):
|
||||
"""Cod necunoscut in nomenclator -> needs_mapping + nemapate negol, erori gol, motiv negol."""
|
||||
r = client.post("/v1/prezentari", json=_body(prestatii=[{"cod_prestatie": "VERIFICARE NECUNOSCUTA 999"}]))
|
||||
res = r.json()["results"][0]
|
||||
assert res["status"] == "needs_mapping"
|
||||
assert res["erori"] == []
|
||||
assert res["nemapate"]
|
||||
assert res["nemapate"][0]["cod_op_service"] == "VERIFICARE NECUNOSCUTA 999"
|
||||
assert res["nemapate"][0]["cod"] == "COD_NEMAPAT"
|
||||
assert res["motiv"]
|
||||
|
||||
|
||||
def test_queued_fara_erori_nemapate_motiv(client):
|
||||
"""Prezentare valida -> queued cu erori/nemapate goale si motiv null."""
|
||||
r = client.post("/v1/prezentari", json=_body())
|
||||
res = r.json()["results"][0]
|
||||
assert res["status"] == "queued"
|
||||
assert res["erori"] == [] and res["nemapate"] == []
|
||||
assert res["motiv"] is None
|
||||
|
||||
|
||||
def test_raspuns_nu_reflecta_parola(client):
|
||||
"""Raspunsul onest nu trebuie sa contina niciodata creds RAR (echo de parola)."""
|
||||
body = _body(data_prestatie="2099-01-01")
|
||||
body["rar_credentials"] = {"email": "x@y.ro", "password": "PAROLA_SECRETA_123"}
|
||||
r = client.post("/v1/prezentari", json=body)
|
||||
assert "PAROLA_SECRETA_123" not in r.text
|
||||
assert "password" not in r.text
|
||||
|
||||
|
||||
def test_json_malformat_422(client):
|
||||
# Lipseste vin -> validare de shape Pydantic -> 422 (NU needs_data).
|
||||
bad = {"rar_credentials": {"email": "x", "password": "y"},
|
||||
|
||||
Reference in New Issue
Block a user