fix: improve maintenance and synchronize live conversations

This commit is contained in:
WangShen007 committed 2026-10-29 09:46:21 +08:00
1 parent bb541bd212
commit ef86a5d3af
297 files changed
+2983 -1274

No files matched your search

+30 -1
View File
@@ -15,6 +15,7 @@ limitations under the License.
"""
from unittest.mock import patch
from datetime import datetime, timezone
from uuid import uuid4
import pytest
@@ -28,7 +29,7 @@ from app.models.ticket import (
TicketSource,
TicketStatus,
)
from app.models.ticket_activity import TicketActivity, TicketActivityType, TicketActorType
from app.models.ticket_activity import TicketActivityType, TicketActorType
from app.services.ticket import NATIVE_INTEGRATION_TYPE, TicketService, render_customer_template
@@ -315,6 +316,34 @@ class TestCustomerEmailPath:
row = db.query(ChatHistory).filter_by(session_id=test_session.session_id).one()
assert deliver.await_args.kwargs["message_id"] == row.id
assert row.attributes["delivery_status"] == "window_expired"
assert ticket.first_response_at is None
assert TicketActivityType.CUSTOMER_NOTIFIED.value not in [
activity.activity_type
for activity in service.activity_repo.list_for_ticket(ticket.id)
]
@pytest.mark.asyncio
async def test_refused_channel_reply_preserves_an_existing_first_response(
self, service, db, test_organization, test_session
):
test_session.channel = "whatsapp"
db.commit()
ticket = make_ticket(service, db, test_organization, session_id=test_session.session_id)
prior_response = datetime(2026, 10, 1, tzinfo=timezone.utc)
ticket.first_response_at = prior_response
db.commit()
db.refresh(ticket)
prior_response = ticket.first_response_at
refused = DeliveryResult(ok=False, reason="window_expired", can_template=True)
with patch("app.services.ticket.deliver_to_customer", return_value=refused):
await service.send_customer_message(ticket, "Your refund is on its way")
assert ticket.first_response_at == prior_response
assert TicketActivityType.CUSTOMER_NOTIFIED.value not in [
activity.activity_type
for activity in service.activity_repo.list_for_ticket(ticket.id)
]
@pytest.mark.asyncio
async def test_a_send_that_raises_is_marked_undelivered(