Files
orion/app/modules/prospecting/tests/unit/test_interaction_service.py
Samir Boulahtit 22ae63b414
Some checks failed
CI / validate (push) Has been cancelled
CI / ruff (push) Successful in 10s
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has started running
refactor(prospecting): migrate SVC-006 transaction control to endpoint level
Move db.commit() from services to API endpoints and Celery tasks.
Services now use db.flush() only; endpoints own the transaction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 16:40:09 +01:00

80 lines
2.6 KiB
Python

# app/modules/prospecting/tests/unit/test_interaction_service.py
"""
Unit tests for InteractionService.
"""
from datetime import date, timedelta
import pytest
from app.modules.prospecting.services.interaction_service import InteractionService
@pytest.mark.unit
@pytest.mark.prospecting
class TestInteractionService:
"""Tests for InteractionService."""
def setup_method(self):
self.service = InteractionService()
def test_create_interaction(self, db, digital_prospect):
"""Test creating an interaction."""
interaction = self.service.create(
db,
prospect_id=digital_prospect.id,
user_id=1,
data={
"interaction_type": "call",
"subject": "Initial call",
"notes": "Discussed website needs",
"outcome": "positive",
},
)
assert interaction.id is not None
itype = interaction.interaction_type
assert (itype.value if hasattr(itype, "value") else itype) == "call"
outcome = interaction.outcome
assert (outcome.value if hasattr(outcome, "value") else outcome) == "positive"
def test_create_interaction_with_follow_up(self, db, digital_prospect):
"""Test creating an interaction with follow-up action."""
follow_up_date = date.today() + timedelta(days=7)
interaction = self.service.create(
db,
prospect_id=digital_prospect.id,
user_id=1,
data={
"interaction_type": "meeting",
"subject": "Office visit",
"next_action": "Send proposal",
"next_action_date": str(follow_up_date),
},
)
assert interaction.next_action == "Send proposal"
def test_get_for_prospect(self, db, digital_prospect, interaction):
"""Test getting interactions for a prospect."""
interactions = self.service.get_for_prospect(db, digital_prospect.id)
assert len(interactions) >= 1
assert interactions[0].prospect_id == digital_prospect.id
def test_get_upcoming_actions(self, db, digital_prospect):
"""Test getting upcoming follow-up actions."""
follow_up_date = date.today() + timedelta(days=3)
self.service.create(
db,
prospect_id=digital_prospect.id,
user_id=1,
data={
"interaction_type": "call",
"next_action": "Follow up",
"next_action_date": str(follow_up_date),
},
)
upcoming = self.service.get_upcoming_actions(db)
assert len(upcoming) >= 1