2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
|
|
|
|
2016-11-10 19:30:09 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2016-09-20 22:51:11 +02:00
|
|
|
class ZenDeskHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "zendesk"
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/zendesk?stream={stream}"
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2024-07-12 02:30:17 +02:00
|
|
|
def get_payload(self, fixture_name: str) -> dict[str, str]:
|
2016-09-20 22:51:11 +02:00
|
|
|
return {
|
2021-02-12 08:20:45 +01:00
|
|
|
"ticket_title": self.TICKET_TITLE,
|
|
|
|
"ticket_id": str(self.TICKET_ID),
|
|
|
|
"message": self.MESSAGE,
|
2024-05-04 22:02:50 +02:00
|
|
|
"stream": self.CHANNEL_NAME,
|
2016-09-20 22:51:11 +02:00
|
|
|
}
|
|
|
|
|
2020-08-24 18:22:16 +02:00
|
|
|
def do_test(self, expected_topic: str, expected_message: str) -> None:
|
2024-05-04 22:04:48 +02:00
|
|
|
self.api_channel_message(
|
2020-08-24 18:22:16 +02:00
|
|
|
self.test_user,
|
|
|
|
"",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type=None,
|
|
|
|
)
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-08-24 18:22:16 +02:00
|
|
|
def test_short_topic(self) -> None:
|
2016-09-20 22:51:11 +02:00
|
|
|
self.TICKET_ID = 4
|
|
|
|
self.TICKET_TITLE = "Test ticket"
|
2020-08-24 18:22:16 +02:00
|
|
|
self.MESSAGE = "some message"
|
|
|
|
self.do_test(
|
2021-02-12 08:20:45 +01:00
|
|
|
expected_topic="#4: Test ticket",
|
2020-08-24 18:22:16 +02:00
|
|
|
expected_message="some message",
|
|
|
|
)
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_long_subject(self) -> None:
|
2016-09-20 22:51:11 +02:00
|
|
|
self.TICKET_ID = 4
|
2020-08-24 18:22:16 +02:00
|
|
|
self.TICKET_TITLE = "Test ticket" + "!" * 80
|
|
|
|
self.MESSAGE = "some message"
|
|
|
|
self.do_test(
|
|
|
|
expected_topic="#4: Test ticket" + "!" * 42 + "...",
|
|
|
|
expected_message="some message",
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_long_content(self) -> None:
|
|
|
|
self.TICKET_ID = 5
|
|
|
|
self.TICKET_TITLE = "Some ticket"
|
|
|
|
self.MESSAGE = "New comment:\n> It is better\n* here"
|
|
|
|
self.do_test(
|
|
|
|
expected_topic="#5: Some ticket",
|
|
|
|
expected_message="New comment:\n> It is better\n* here",
|
|
|
|
)
|