test(api): add tests for campaign dispatch, pixel tracking, and flow execute endpoint
This commit is contained in:
parent
02c9cf02a7
commit
f51055cea5
1 changed files with 59 additions and 0 deletions
59
tests/test_api_endpoints.py
Normal file
59
tests/test_api_endpoints.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
from django.test import TestCase
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework.test import APIClient
|
||||
from outreach.models import EmailTemplate, Campaign, CampaignRecipient
|
||||
from workflows.models import FlowDefinition, FlowExecutionLog
|
||||
import uuid
|
||||
|
||||
class TestOutreachAndWorkflowEndpoints(TestCase):
|
||||
def setUp(self):
|
||||
self.user = User.objects.create_user(username='testuser', password='password123')
|
||||
self.client = APIClient()
|
||||
self.client.force_authenticate(user=self.user)
|
||||
|
||||
def test_outreach_campaign_dispatch_api(self):
|
||||
template = EmailTemplate.objects.create(
|
||||
name='Promo',
|
||||
subject='Hello {{ first_name }}',
|
||||
body_html='<p>Hi {{ first_name }}</p>',
|
||||
body_text='Hi {{ first_name }}'
|
||||
)
|
||||
campaign = Campaign.objects.create(
|
||||
name='Summer Campaign',
|
||||
template=template,
|
||||
status='draft'
|
||||
)
|
||||
CampaignRecipient.objects.create(
|
||||
campaign=campaign,
|
||||
email='lead@example.com',
|
||||
first_name='Alice',
|
||||
last_name='Smith'
|
||||
)
|
||||
resp = self.client.post(f'/api/campaigns/{campaign.id}/dispatch/')
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(resp.data['status'], 'dispatched')
|
||||
self.assertEqual(resp.data['sent_count'], 1)
|
||||
|
||||
def test_track_email_open_view(self):
|
||||
token = uuid.uuid4()
|
||||
template = EmailTemplate.objects.create(name='T', subject='S', body_html='B')
|
||||
campaign = Campaign.objects.create(name='C', template=template)
|
||||
CampaignRecipient.objects.create(campaign=campaign, email='a@b.com', tracking_token=token)
|
||||
|
||||
anon_client = APIClient()
|
||||
resp = anon_client.get(f'/api/track/{token}/')
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(resp.get('Content-Type'), 'image/gif')
|
||||
|
||||
def test_workflow_execute_api(self):
|
||||
flow = FlowDefinition.objects.create(
|
||||
name='Lead Scoring Flow',
|
||||
graph={
|
||||
'nodes': [{'id': 'n1', 'type': 'action', 'data': {'action': 'increment_score', 'points': 10}}],
|
||||
'edges': []
|
||||
}
|
||||
)
|
||||
resp = self.client.post(f'/api/workflows/{flow.id}/execute/', {'context': {'lead_id': 1, 'score': 5}}, format='json')
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(resp.data['status'], 'completed')
|
||||
self.assertEqual(resp.data['context_data']['score'], 15)
|
||||
Loading…
Reference in a new issue