2018-01-07 12:05:44 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2018-01-07 12:05:44 +01:00
|
|
|
class GrooveHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "groove"
|
2021-02-12 08:20:45 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/groove?stream={stream}&api_key={api_key}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "groove"
|
2018-01-07 12:05:44 +01:00
|
|
|
|
|
|
|
# This test simulates the condition when a new ticket comes.
|
|
|
|
def test_groove_ticket_started(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "notifications"
|
2019-04-18 22:23:36 +02:00
|
|
|
expected_message = """
|
|
|
|
Test Name submitted new ticket [#9: Test Subject](https://ghostfox.groovehq.com/groove_client/tickets/68659446):
|
|
|
|
|
|
|
|
``` quote
|
|
|
|
The content of the body goes here.
|
|
|
|
```
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"ticket_started",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2018-01-07 12:05:44 +01:00
|
|
|
|
|
|
|
# This simulates the condition when a ticket
|
|
|
|
# is assigned to an agent.
|
|
|
|
def test_groove_ticket_assigned_agent_only(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "notifications"
|
2019-04-18 22:23:36 +02:00
|
|
|
expected_message = "[#9: Test Subject](https://testteam.groovehq.com/groove_client/tickets/68659446) (open) assigned to agent@example.com."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"ticket_assigned__agent_only",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2018-01-07 12:05:44 +01:00
|
|
|
|
|
|
|
# This simulates the condition when a ticket
|
|
|
|
# is assigned to an agent in a group.
|
|
|
|
def test_groove_ticket_assigned_agent_and_group(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "notifications"
|
2019-04-18 22:23:36 +02:00
|
|
|
expected_message = "[#9: Test Subject](https://testteam.groovehq.com/groove_client/tickets/68659446) (open) assigned to agent@example.com from group2."
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"ticket_assigned__agent_and_group",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2018-01-07 12:05:44 +01:00
|
|
|
|
|
|
|
# This simulates the condition when a ticket
|
|
|
|
# is assigned to a group.
|
|
|
|
def test_groove_ticket_assigned_group_only(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "notifications"
|
2019-04-18 22:23:36 +02:00
|
|
|
expected_message = "[#9: Test Subject](https://testteam.groovehq.com/groove_client/tickets/68659446) (pending) assigned to group2."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"ticket_assigned__group_only",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2018-01-07 12:05:44 +01:00
|
|
|
|
|
|
|
# This simulates the condition when a ticket
|
|
|
|
# is assigned to no one.
|
|
|
|
def test_groove_ticket_assigned_no_one(self) -> None:
|
2024-05-04 22:02:50 +02:00
|
|
|
self.subscribe(self.test_user, self.CHANNEL_NAME)
|
2021-02-12 08:19:30 +01:00
|
|
|
result = self.client_post(
|
|
|
|
self.url,
|
2021-02-12 08:20:45 +01:00
|
|
|
self.get_body("ticket_assigned__no_one"),
|
2021-02-12 08:19:30 +01:00
|
|
|
content_type="application/x-www-form-urlencoded",
|
2021-02-12 08:20:45 +01:00
|
|
|
HTTP_X_GROOVE_EVENT="ticket_assigned",
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2018-01-07 12:05:44 +01:00
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
# This simulates the notification when an agent replied to a ticket.
|
|
|
|
def test_groove_agent_replied(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "notifications"
|
2019-04-18 22:23:36 +02:00
|
|
|
expected_message = """
|
|
|
|
agent@example.com replied to [ticket #776](https://ghostfox.groovehq.com/groove_client/tickets/68667295):
|
|
|
|
|
|
|
|
``` quote
|
|
|
|
Hello , This is a reply from an agent to a ticket
|
|
|
|
```
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"agent_replied",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2018-01-07 12:05:44 +01:00
|
|
|
|
|
|
|
# This simulates the condition when a customer replied to a ticket.
|
|
|
|
def test_groove_customer_replied(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "notifications"
|
2019-04-18 22:23:36 +02:00
|
|
|
expected_message = """
|
|
|
|
rambo@example.com replied to [ticket #440](https://ghostfox.groovehq.com/groove_client/tickets/68666538):
|
|
|
|
|
|
|
|
``` quote
|
|
|
|
Hello agent, thanks for getting back. This is how a reply from customer looks like.
|
|
|
|
```
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"customer_replied",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2018-01-07 12:05:44 +01:00
|
|
|
|
|
|
|
# This simulates the condition when an agent left a note.
|
|
|
|
def test_groove_note_added(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "notifications"
|
2019-04-18 22:23:36 +02:00
|
|
|
expected_message = """
|
|
|
|
anotheragent@example.com left a note on [ticket #776](https://ghostfox.groovehq.com/groove_client/tickets/68667295):
|
|
|
|
|
|
|
|
``` quote
|
|
|
|
This is a note added to a ticket
|
|
|
|
```
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"note_added",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-ww-form-urlencoded",
|
|
|
|
)
|