fix some bugs
This commit is contained in:
1 parent
b8b3aba855
commit
963fd839dc
22 files changed
+570
-33
No files matched your search
+89
-1
@@ -140,10 +140,11 @@ def test_unit_notification_destinations_normalize_and_reject_duplicate_superviso
|
||||
slug="notification-destinations",
|
||||
supervisor_mobile_1="0912 111 2233",
|
||||
supervisor_mobile_2="0935 222 3344",
|
||||
supervisor_mobile_4="0990 444 5566",
|
||||
)
|
||||
unit.full_clean()
|
||||
unit.save()
|
||||
assert unit.supervisor_mobiles == ("+989121112233", "+989352223344")
|
||||
assert unit.supervisor_mobiles == ("+989121112233", "+989352223344", "+989904445566")
|
||||
|
||||
unit.supervisor_mobile_3 = "09121112233"
|
||||
with pytest.raises(ValidationError, match="قبلاً"):
|
||||
@@ -158,6 +159,7 @@ def test_new_ticket_sms_is_queued_for_each_unit_supervisor_only_on_creation(cate
|
||||
unit.supervisor_mobile_1 = "09121112233"
|
||||
unit.supervisor_mobile_2 = "09352223344"
|
||||
unit.supervisor_mobile_3 = "09903334455"
|
||||
unit.supervisor_mobile_4 = "09214445566"
|
||||
unit.save()
|
||||
ticket = create_ticket(customer=customer, category=category, subject=" پیگیری بارگیری ", body="متن")
|
||||
jobs = list(NotificationJob.objects.filter(ticket=ticket, event_type="UNIT_SUPERVISOR_NEW_TICKET").order_by("id"))
|
||||
@@ -180,12 +182,98 @@ def test_new_ticket_sms_is_queued_for_each_unit_supervisor_only_on_creation(cate
|
||||
assert customer.local_mobile in message
|
||||
assert "موضوع: پیگیری بارگیری" in message
|
||||
assert f"دسته: {category.title}" in message
|
||||
assert "ارجاع: صف عمومی" in message
|
||||
|
||||
supervisor_job_count = NotificationJob.objects.filter(event_type="UNIT_SUPERVISOR_NEW_TICKET").count()
|
||||
reply_ticket(ticket_id=ticket.pk, user=customer, body="پاسخ جدید")
|
||||
assert NotificationJob.objects.filter(event_type="UNIT_SUPERVISOR_NEW_TICKET").count() == supervisor_job_count
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_unit_supervisor_sms_uses_editable_unit_template_and_selected_expert(category, customer, monkeypatch):
|
||||
from apps.notifications.management.commands.process_notifications import _send_sms
|
||||
from apps.notifications.models import SMSTemplate
|
||||
from apps.customers.models import CustomerProfile
|
||||
|
||||
unit = category.unit
|
||||
unit.supervisor_mobile_1 = "09125556677"
|
||||
unit.save()
|
||||
expert = make_staff("selected-supervisor-sms-expert")
|
||||
expert.staff_profile.display_name = "کارشناس انتخابی پیامک"
|
||||
expert.staff_profile.primary_unit = unit
|
||||
expert.staff_profile.save()
|
||||
CustomerProfile.objects.create(user=customer, first_name="سارا", last_name="احمدی")
|
||||
template = SMSTemplate.objects.create(
|
||||
unit=unit,
|
||||
event_type=SMSTemplate.Event.UNIT_SUPERVISOR_NEW_TICKET,
|
||||
title="الگوی سفارشی سرپرستان",
|
||||
body="{first_name} {last_name} | {unit_name} | {ticket_number} | {customer_mobile} | {category_name} | {expert_name}",
|
||||
)
|
||||
template.full_clean()
|
||||
ticket = create_ticket(
|
||||
customer=customer, category=category, subject="تست الگوی قابل تنظیم",
|
||||
selected_expert=expert, body="متن",
|
||||
)
|
||||
job = NotificationJob.objects.get(ticket=ticket, event_type=SMSTemplate.Event.UNIT_SUPERVISOR_NEW_TICKET)
|
||||
sent = []
|
||||
|
||||
class Provider:
|
||||
def send_message(self, mobile, message):
|
||||
sent.append((mobile, message))
|
||||
return type("Result", (), {"success": True})()
|
||||
|
||||
monkeypatch.setattr("apps.notifications.management.commands.process_notifications.get_sms_provider", lambda: Provider())
|
||||
_send_sms(job)
|
||||
assert sent == [(
|
||||
"+989125556677",
|
||||
f"سارا احمدی | {unit.name} | {ticket.ticket_number} | {customer.local_mobile} | {category.title} | کارشناس انتخابی پیامک",
|
||||
)]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_unit_supervisor_sms_handles_missing_customer_names_and_general_queue(category, customer, monkeypatch):
|
||||
from apps.notifications.management.commands.process_notifications import _send_sms
|
||||
from apps.notifications.models import SMSTemplate
|
||||
|
||||
category.unit.supervisor_mobile_1 = "09125556677"
|
||||
category.unit.save()
|
||||
SMSTemplate.objects.create(
|
||||
unit=category.unit,
|
||||
event_type=SMSTemplate.Event.UNIT_SUPERVISOR_NEW_TICKET,
|
||||
title="الگوی نام خالی سرپرستان",
|
||||
body="نام: {first_name} {last_name}\nنام جایگزین: {recipient_name}\nارجاع: {expert_name}",
|
||||
)
|
||||
ticket = create_ticket(customer=customer, category=category, subject="مشتری بدون نام", body="متن")
|
||||
job = NotificationJob.objects.get(ticket=ticket, event_type=SMSTemplate.Event.UNIT_SUPERVISOR_NEW_TICKET)
|
||||
sent = []
|
||||
|
||||
class Provider:
|
||||
def send_message(self, mobile, message):
|
||||
sent.append((mobile, message))
|
||||
return type("Result", (), {"success": True})()
|
||||
|
||||
monkeypatch.setattr("apps.notifications.management.commands.process_notifications.get_sms_provider", lambda: Provider())
|
||||
_send_sms(job)
|
||||
|
||||
assert sent == [(
|
||||
"+989125556677",
|
||||
"نام: \nنام جایگزین: ثبت نشده\nارجاع: صف عمومی",
|
||||
)]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_global_supervisor_sms_template_is_seeded_and_editable():
|
||||
from apps.notifications.models import SMSTemplate
|
||||
|
||||
template = SMSTemplate.objects.get(
|
||||
unit__isnull=True, event_type=SMSTemplate.Event.UNIT_SUPERVISOR_NEW_TICKET
|
||||
)
|
||||
assert "{expert_name}" in template.body
|
||||
assert "{customer_mobile}" in template.body
|
||||
assert "{category_name}" in template.body
|
||||
assert {"expert_name", "customer_mobile", "category_name"}.issubset(template.allowed_tags)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_staff_created_ticket_also_notifies_owning_unit_supervisors(category, customer):
|
||||
category.unit.supervisor_mobile_1 = "09124445566"
|
||||
|
||||
Reference in new issue
Block a user