Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark status as completed when flow is started #620

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions eventstore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,6 @@ def update_whatsapp_template_send_status(message_id, preferred_channel=None):
if preferred_channel:
status.preferred_channel = preferred_channel

status.save()

if status.flow_uuid:
extra = status.data
extra["preferred_channel"] = status.preferred_channel
Expand All @@ -853,6 +851,10 @@ def update_whatsapp_template_send_status(message_id, preferred_channel=None):
flow=str(status.flow_uuid),
contacts=[str(status.contact_uuid)],
)
status.status = WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED
status.action_completed_at = timezone.now()

status.save()
except WhatsAppTemplateSendStatus.DoesNotExist:
pass

Expand Down Expand Up @@ -881,3 +883,6 @@ def process_whatsapp_template_send_status():
flow=str(status.flow_uuid),
contacts=[str(status.contact_uuid)],
)
status.status = WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED
status.action_completed_at = timezone.now()
status.save()
20 changes: 17 additions & 3 deletions eventstore/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
import uuid
from unittest import mock

import requests
Expand Down Expand Up @@ -955,18 +956,20 @@ def test_update_status_whatsapp_ready(self, mock_flow_start):
If the event is received and it has a flow to start, the status record needs to
be updated and the async_create_flow_start task needs to be called
"""
self.status.flow_uuid = "flow-uuid"
self.status.flow_uuid = uuid.uuid4()
self.status.save()
tasks.update_whatsapp_template_send_status(self.status.message_id)

self.status.refresh_from_db()

self.assertEqual(
self.status.status, WhatsAppTemplateSendStatus.Status.EVENT_RECEIVED
self.status.status, WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED
)
self.assertEqual(self.status.preferred_channel, "WhatsApp")
self.assertIsNotNone(self.status.event_received_at)
self.assertIsNotNone(self.status.action_completed_at)

mock_flow_start.assert_not_called()
mock_flow_start.assert_called()

@mock.patch("eventstore.tasks.async_create_flow_start")
def test_update_status_sms(self, mock_flow_start):
Expand Down Expand Up @@ -1047,3 +1050,14 @@ def test_starts_flows(self, mock_async_flow_start):
),
],
)

self.status_ready.refresh_from_db()
self.status_expired.refresh_from_db()

self.assertEqual(
self.status_ready.status, WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED
)
self.assertEqual(
self.status_expired.status,
WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED,
)
Loading