add retry sms manually
This commit is contained in:
1 parent
33930e972c
commit
cb92abbb41
42 files changed
+1628
-1484
No files matched your search
+54
-2
@@ -9,6 +9,7 @@ from apps.staff.models import OrganizationalUnit, StaffProfile
|
||||
from apps.tickets.models import Ticket, TicketCategory
|
||||
from apps.tickets.services import create_ticket, claim_ticket, reply_ticket
|
||||
from apps.messaging.models import Message,MessageReadReceipt
|
||||
from apps.notifications.models import NotificationJob
|
||||
from apps.customers.models import CustomerProfile
|
||||
from apps.core.persian_text import normalize_persian_text
|
||||
|
||||
@@ -256,8 +257,6 @@ def test_staff_reply_feedback_and_new_reply_action_remain_available(client):
|
||||
@pytest.mark.django_db
|
||||
def test_staff_ticket_sms_status_is_compact_expandable_and_time_precise(client):
|
||||
from apps.core.templatetags.jalali import jalali_datetime
|
||||
from apps.notifications.models import NotificationJob
|
||||
|
||||
category=TicketCategory.objects.create(title="رهگیری پیامک",slug="sms-timeline")
|
||||
customer=User.objects.create_user(username="sms-timeline-customer",mobile="09120000031",account_type="CUSTOMER")
|
||||
expert=User.objects.create_user(username="sms-timeline-expert",mobile="09120000032",account_type="STAFF")
|
||||
@@ -288,6 +287,59 @@ def test_staff_ticket_sms_status_is_compact_expandable_and_time_precise(client):
|
||||
assert jalali_datetime(delivered_at) in content
|
||||
assert "123456789" in content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_staff_can_manually_retry_only_failed_sms_for_the_current_ticket(client):
|
||||
category=TicketCategory.objects.create(title="تلاش مجدد پیامک",slug="manual-sms-retry")
|
||||
customer=User.objects.create_user(username="sms-retry-customer",mobile="09120000041",account_type="CUSTOMER")
|
||||
expert=User.objects.create_user(username="sms-retry-expert",mobile="09120000042",account_type="STAFF")
|
||||
outsider=User.objects.create_user(username="sms-retry-outsider",mobile="09120000043",account_type="STAFF")
|
||||
StaffProfile.objects.create(user=expert,display_name="کارشناس تلاش مجدد")
|
||||
StaffProfile.objects.create(user=outsider,display_name="کارشناس نامرتبط")
|
||||
ticket=create_ticket(customer=customer,category=category,subject="بررسی retry پیامک",selected_expert=expert,body="شرح")
|
||||
failed_job=NotificationJob.objects.get(ticket=ticket,event_type="CUSTOMER_TICKET_CREATED")
|
||||
NotificationJob.objects.filter(pk=failed_job.pk).update(
|
||||
status=NotificationJob.Status.FAILED,attempts=4,last_error="خطای درگاه",
|
||||
provider_message_id="failed-provider-id",provider_status_code="-19",
|
||||
delivery_status=NotificationJob.DeliveryStatus.ERROR,delivery_status_code="-19",
|
||||
delivery_description="ارسال قطعی ناموفق بود.",delivery_checked_at=timezone.now(),
|
||||
delivery_check_attempts=3,delivery_is_final=True,
|
||||
)
|
||||
failed_job.refresh_from_db()
|
||||
provisional_job=NotificationJob.objects.create(
|
||||
channel=NotificationJob.Channel.SMS,event_type="STAFF_REPLY",ticket=ticket,customer=customer,
|
||||
status=NotificationJob.Status.SENT,next_attempt_at=timezone.now(),dedupe_key="test:provisional-manual-retry",
|
||||
delivery_status=NotificationJob.DeliveryStatus.UNKNOWN,delivery_next_check_at=timezone.now()+timedelta(minutes=3),
|
||||
)
|
||||
retry_url=reverse("staff_tickets:sms_retry",args=[ticket.public_id,failed_job.pk])
|
||||
provisional_retry_url=reverse("staff_tickets:sms_retry",args=[ticket.public_id,provisional_job.pk])
|
||||
|
||||
client.force_login(expert)
|
||||
content=client.get(reverse("staff_tickets:detail",args=[ticket.public_id])).content.decode()
|
||||
assert retry_url in content
|
||||
assert 'aria-label="تلاش مجدد برای ارسال این پیامک"' in content
|
||||
assert provisional_retry_url not in content
|
||||
assert client.get(retry_url).status_code==405
|
||||
|
||||
client.force_login(outsider)
|
||||
assert client.post(retry_url).status_code==403
|
||||
failed_job.refresh_from_db()
|
||||
assert failed_job.status==NotificationJob.Status.FAILED
|
||||
|
||||
client.force_login(expert)
|
||||
response=client.post(retry_url,follow=True)
|
||||
assert response.status_code==200
|
||||
assert "پیامک ناموفق دوباره در صف ارسال قرار گرفت." in response.content.decode()
|
||||
failed_job.refresh_from_db(); provisional_job.refresh_from_db()
|
||||
assert failed_job.status==NotificationJob.Status.PENDING
|
||||
assert failed_job.attempts==0 and failed_job.next_attempt_at<=timezone.now()
|
||||
assert failed_job.last_error=="" and failed_job.provider_message_id=="" and failed_job.provider_status_code==""
|
||||
assert failed_job.sent_at is None and failed_job.delivery_status=="" and failed_job.delivery_status_code==""
|
||||
assert failed_job.delivery_description=="" and failed_job.delivery_checked_at is None
|
||||
assert failed_job.delivery_check_attempts==0 and failed_job.delivery_next_check_at is None
|
||||
assert failed_job.delivery_is_final is False
|
||||
assert provisional_job.status==NotificationJob.Status.SENT
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_staff_sidebar_hides_admin_link_and_shows_developer_credit(client):
|
||||
expert=User.objects.create_superuser(username="sidebar-admin",mobile="09384999655",password="test-pass",account_type="STAFF")
|
||||
|
||||
Reference in new issue
Block a user