|
5 | 5 | import respx
|
6 | 6 | from core.integrations.github import GITHUB_API_URL
|
7 | 7 | from core.models import DiscordMessage, Webhook
|
8 |
| -from core.tasks import process_github_webhook, process_internal_webhook, process_webhook |
| 8 | +from core.tasks import process_github_webhook, process_internal_webhook, process_webhook, process_zammad_webhook |
9 | 9 | from django.utils import timezone
|
10 | 10 | from django_tasks.task import ResultStatus
|
11 | 11 | from httpx import Response
|
@@ -167,3 +167,52 @@ def test_process_github_webhook_creates_a_message_from_supported(
|
167 | 167 | " from **Done** to **In progress**"
|
168 | 168 | )
|
169 | 169 | assert dm.sent_at is None
|
| 170 | + |
| 171 | + |
| 172 | +@pytest.mark.django_db |
| 173 | +@respx.mock |
| 174 | +def test_process_zammad_webhook_creates_a_message_from_supported_queue(): |
| 175 | + wh = Webhook.objects.create( |
| 176 | + source="zammad", |
| 177 | + event="", |
| 178 | + meta={}, |
| 179 | + content={ |
| 180 | + "ticket": { |
| 181 | + "id": 123, |
| 182 | + "group": {"id": "123", "name": "TestZammad Helpdesk"}, |
| 183 | + "updated_by": {"firstname": "Cookie", "lastname": "Monster"}, |
| 184 | + "title": "Test Ticket Title", |
| 185 | + "owner": {"firstname": "Kermit", "lastname": "TheFrog"}, |
| 186 | + "state": "open", |
| 187 | + "number": "13374321", |
| 188 | + "customer": {"firstname": "Cookie", "lastname": "Monster"}, |
| 189 | + "created_at": str(timezone.now()), |
| 190 | + "updated_at": str(timezone.now()), |
| 191 | + "article_ids": [1], |
| 192 | + }, |
| 193 | + "article": { |
| 194 | + "sender": "Customer", |
| 195 | + "internal": False, |
| 196 | + "ticket_id": 123, |
| 197 | + "created_at": str(timezone.now()), |
| 198 | + "created_by": {"firstname": "Cookie", "lastname": "Monster"}, |
| 199 | + "subject": "New Cookies please", |
| 200 | + }, |
| 201 | + }, |
| 202 | + extra={}, |
| 203 | + ) |
| 204 | + |
| 205 | + process_zammad_webhook(wh) |
| 206 | + |
| 207 | + dm = DiscordMessage.objects.get() |
| 208 | + assert wh.processed_at is not None |
| 209 | + assert wh.processed_at < timezone.now() |
| 210 | + assert wh.event == "new_ticket_created" |
| 211 | + assert dm.channel_id == settings.DISCORD_HELPDESK_CHANNEL_ID |
| 212 | + assert dm.channel_name == settings.DISCORD_HELPDESK_CHANNEL_NAME |
| 213 | + assert dm.content == ( |
| 214 | + "Zammad: " |
| 215 | + "TestZammad Helpdesk: Cookie created new ticket " |
| 216 | + "https://servicedesk.europython.eu/#ticket/zoom/123" |
| 217 | + ) |
| 218 | + assert dm.sent_at is None |
0 commit comments