feat(maria): profil de client (firma), asociat cu mai multe numere
Un client poate avea mai multi angajati care scriu pe WhatsApp de pe numere diferite; toti gasesc acum acelasi profil (rag/client.py, ~/.maria-bridge/clients.json). Profilul intra in prompt sub o sectiune DESPRE CLIENT, la fiecare mesaj, stateless ca restul Mariei — dar nu atinge cautarea/scorul din rag/rank.py, ca sa nu strice pragurile deja calibrate. Administrare din dashboard (sectiune noua "Clienti cunoscuti"), nu din chat, ca sa ramana pe canalul autentificat. 117/117 teste maria-whatsapp-bridge + teste noi pentru rutele de dashboard. Co-Authored-By: Claude Agent <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""Teste pentru CRUD-ul de clienti Maria din dashboard/api.py.
|
||||
|
||||
Nu trece prin server HTTP (nici documentele Maria n-o fac in suita existenta) —
|
||||
apeleaza direct functiile, cu MARIA_STATE_DIR/MARIA_CLIENTS_FILE mutate in tmp.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
sys.path.insert(0, str(ROOT / "dashboard"))
|
||||
|
||||
api = pytest.importorskip("api", reason="dashboard/api.py")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def maria_dir(tmp_path, monkeypatch):
|
||||
d = tmp_path / "maria-bridge"
|
||||
d.mkdir()
|
||||
monkeypatch.setattr(api, "MARIA_STATE_DIR", d)
|
||||
monkeypatch.setattr(api, "MARIA_CLIENTS_FILE", d / "clients.json")
|
||||
return d
|
||||
|
||||
|
||||
def test_salveaza_si_listeaza():
|
||||
api.maria_save_client("acme", "ACME SRL", "Distributie", ["+40 712 345 678", "40799887766"])
|
||||
clienti = api.maria_clients()
|
||||
assert clienti == [{"id": "acme", "nume": "ACME SRL", "profil": "Distributie",
|
||||
"numere": ["40712345678", "40799887766"]}]
|
||||
|
||||
|
||||
def test_id_invalid_respins():
|
||||
with pytest.raises(ValueError):
|
||||
api.maria_save_client("ACME!", "x", "y", [])
|
||||
|
||||
|
||||
def test_numar_furat_de_la_alt_client_respins(maria_dir):
|
||||
api.maria_save_client("acme", "ACME SRL", "p", ["40712345678"])
|
||||
with pytest.raises(ValueError):
|
||||
api.maria_save_client("beta", "Beta SRL", "p", ["40712345678"])
|
||||
# nemodificat
|
||||
date = json.loads((maria_dir / "clients.json").read_text(encoding="utf-8"))
|
||||
assert list(date.keys()) == ["acme"]
|
||||
|
||||
|
||||
def test_reasocia_numarul_la_acelasi_client_e_permis():
|
||||
api.maria_save_client("acme", "ACME SRL", "p1", ["40712345678"])
|
||||
api.maria_save_client("acme", "ACME SRL", "p2", ["40712345678", "40799887766"])
|
||||
assert api.maria_clients()[0]["profil"] == "p2"
|
||||
|
||||
|
||||
def test_sterge():
|
||||
api.maria_save_client("acme", "ACME SRL", "p", [])
|
||||
assert api.maria_delete_client("acme") is True
|
||||
assert api.maria_clients() == []
|
||||
assert api.maria_delete_client("acme") is False
|
||||
Reference in New Issue
Block a user