Skip to content

Commit

Permalink
Merge pull request #619 from praekeltfoundation/fix-capi-events
Browse files Browse the repository at this point in the history
Ignore events after action is completed
  • Loading branch information
erikh360 authored Aug 18, 2024
2 parents 464d620 + 4cb4534 commit c0f15be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions eventstore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,10 @@ def update_whatsapp_template_send_status(message_id, preferred_channel=None):
status = WhatsAppTemplateSendStatus.objects.get(
message_id=message_id, event_received_at__isnull=True
)

if status.status == WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED:
return

status.event_received_at = timezone.now()
status.status = WhatsAppTemplateSendStatus.Status.EVENT_RECEIVED

Expand Down
18 changes: 18 additions & 0 deletions eventstore/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,24 @@ def test_update_status_sms(self, mock_flow_start):
self.assertIsNotNone(self.status.event_received_at)
mock_flow_start.assert_not_called()

@mock.patch("eventstore.tasks.async_create_flow_start")
def test_update_status_action_completed(self, mock_flow_start):
"""
If the status record is already action_completed then do nothing.
"""
self.status.status = WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED
self.status.save()
tasks.update_whatsapp_template_send_status(self.status.message_id, "SMS")

self.status.refresh_from_db()

self.assertEqual(
self.status.status, WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED
)
self.assertEqual(self.status.preferred_channel, "WhatsApp")
self.assertIsNone(self.status.event_received_at)
mock_flow_start.assert_not_called()


class ProcessWhatsAppTemplateSendStatusTests(TestCase):
def setUp(self):
Expand Down

0 comments on commit c0f15be

Please sign in to comment.