2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
|
|
|
|
2016-10-29 04:00:02 +02:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
|
|
# Tests for the Desk.com webhook integration.
|
|
|
|
#
|
2024-05-04 22:39:36 +02:00
|
|
|
# The channel name must be provided in the URL-encoded test fixture data,
|
2024-05-04 22:02:50 +02:00
|
|
|
# and must match CHANNEL_NAME set here.
|
2016-10-29 04:00:02 +02:00
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# stream=deskdotcom&topic=static%20text%20notification&data=This%20is%20a%20custom%20action.
|
|
|
|
#
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2016-10-29 04:00:02 +02:00
|
|
|
class DeskDotComHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "deskdotcom"
|
2018-03-13 23:43:02 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/deskdotcom?stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "deskdotcom"
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_static_text_message(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "static text notification"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = "This is a custom action."
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2024-05-04 22:04:48 +02:00
|
|
|
self.api_channel_message(
|
2021-02-12 08:19:30 +01:00
|
|
|
self.test_user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"static_text",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_case_updated_message(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "case updated notification"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Case 2 updated. "
|
|
|
|
"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
|
|
"I have a question</a>"
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2024-05-04 22:04:48 +02:00
|
|
|
self.api_channel_message(
|
2021-02-12 08:19:30 +01:00
|
|
|
self.test_user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"case_updated",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_unicode_text_italian(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "case updated notification"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Case 2 updated. "
|
|
|
|
"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
|
|
"Il mio hovercraft è pieno di anguille.</a>"
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2024-05-04 22:04:48 +02:00
|
|
|
self.api_channel_message(
|
2021-02-12 08:19:30 +01:00
|
|
|
self.test_user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"unicode_text_italian",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_unicode_text_japanese(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "case updated notification"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Case 2 updated. "
|
|
|
|
"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
|
|
"私のホバークラフトは鰻でいっぱいです</a>"
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2024-05-04 22:04:48 +02:00
|
|
|
self.api_channel_message(
|
2021-02-12 08:19:30 +01:00
|
|
|
self.test_user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"unicode_text_japanese",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2018-05-10 19:34:01 +02:00
|
|
|
def get_body(self, fixture_name: str) -> str:
|
2018-04-20 03:57:21 +02:00
|
|
|
return self.webhook_fixture_data("deskdotcom", fixture_name, file_type="txt")
|