| from __future__ import annotations |
|
|
| from app import customers |
| from app.models import Customer |
|
|
|
|
| async def test_remember_finds_or_creates_and_merges(db_session): |
| c1 = await customers.remember(db_session, 1, shopify_customer_id="C9", name="María") |
| assert c1 is not None and c1.shopify_customer_id == "C9" and c1.name == "María" |
| |
| c2 = await customers.remember(db_session, 1, shopify_customer_id="C9", email="Maria@X.com") |
| assert c2.id == c1.id and c2.email == "maria@x.com" |
| |
| c3 = await customers.remember(db_session, 1, email="maria@x.com") |
| assert c3.id == c1.id |
| |
| assert await customers.remember(db_session, 1) is None |
|
|
|
|
| async def test_remember_is_tenant_isolated(db_session): |
| a = await customers.remember(db_session, 1, email="x@x.com", name="A") |
| b = await customers.remember(db_session, 2, email="x@x.com", name="B") |
| assert a.id != b.id |
| found2 = await customers.remember(db_session, 2, email="x@x.com") |
| assert found2.id == b.id and found2.id != a.id |
|
|
|
|
| def test_returning_note_only_for_returning(): |
| assert customers.returning_note(None) == "" |
| assert customers.returning_note(Customer(tenant_id=1, name="Ana", chats=0)) == "" |
| note = customers.returning_note(Customer(tenant_id=1, name="Ana", chats=2, last_topic="envíos")) |
| assert "CLIENTE QUE VUELVE" in note and "Ana" in note and "envíos" in note |
|
|