feat(crm): dominio backend (cuentas, contactos, prospectos, embudos, oportunidades, actividades)
- Nuevo schema `crm` con 7 tablas multi-tenant (TenantScopedMixin + soft delete) - Módulos FastAPI por dominio: models/dto/service/routes (patrón example) - Métricas del dashboard (KPIs + embudo por etapa) - Conversión de prospecto → cuenta/contacto/oportunidad (idempotente) - Movimiento de oportunidad entre etapas (Kanban) con estado/probabilidad derivados - 25 permisos registrados en PermissionRegistry - Migración Alembic con upgrade/downgrade completos - 24 tests de servicios (pytest) en verde Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
38
backend/tests/test_activities.py
Normal file
38
backend/tests/test_activities.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from api.v1.modules.crm.activities import service
|
||||
from api.v1.modules.crm.activities.dto import ActivityCreate
|
||||
|
||||
T, C = 1, 1
|
||||
|
||||
|
||||
def test_create_rejects_invalid_type(db):
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
service.create_activity(db, ActivityCreate(activity_type="invalido", subject="x"), T, C)
|
||||
assert exc.value.status_code == 422
|
||||
|
||||
|
||||
def test_complete_activity_sets_timestamp(db):
|
||||
activity = service.create_activity(db, ActivityCreate(activity_type="call", subject="Llamar al cliente"), T, C)
|
||||
assert activity.status == "pending"
|
||||
done = service.complete_activity(db, activity.id, T, C)
|
||||
assert done.status == "completed"
|
||||
assert done.completed_at is not None
|
||||
|
||||
|
||||
def test_create_rejects_unknown_related_entity(db):
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
service.create_activity(
|
||||
db, ActivityCreate(activity_type="task", subject="x", opportunity_id=999), T, C
|
||||
)
|
||||
assert exc.value.status_code == 422
|
||||
|
||||
|
||||
def test_filter_by_type_and_status(db):
|
||||
service.create_activity(db, ActivityCreate(activity_type="call", subject="a"), T, C)
|
||||
service.create_activity(db, ActivityCreate(activity_type="meeting", subject="b"), T, C)
|
||||
calls = service.get_activities(db, T, C, activity_type="call")
|
||||
assert len(calls) == 1 and calls[0].activity_type == "call"
|
||||
pending = service.get_activities(db, T, C, activity_status="pending")
|
||||
assert len(pending) == 2
|
||||
Reference in New Issue
Block a user