2020-05-26 07:16:25 +02:00
|
|
|
from unittest.mock import MagicMock, patch
|
2019-03-28 21:32:28 +01:00
|
|
|
|
2018-01-06 12:11:44 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2018-01-06 12:11:44 +01:00
|
|
|
class IntercomWebHookTests(WebhookTestCase):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "test"
|
2018-01-06 12:11:44 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/intercom?&api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "intercom"
|
2018-01-06 12:11:44 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
@patch("zerver.webhooks.intercom.view.check_send_webhook_message")
|
2019-03-28 21:32:28 +01:00
|
|
|
def test_ping_ignore(self, check_send_webhook_message_mock: MagicMock) -> None:
|
|
|
|
self.url = self.build_webhook_url()
|
2021-02-12 08:20:45 +01:00
|
|
|
payload = self.get_body("ping")
|
2019-03-28 21:32:28 +01:00
|
|
|
result = self.client_post(self.url, payload, content_type="application/json")
|
|
|
|
self.assertFalse(check_send_webhook_message_mock.called)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
def test_company_created(self) -> None:
|
|
|
|
expected_topic = "Companies"
|
|
|
|
expected_message = """
|
|
|
|
New company **Kandra Labs** created:
|
|
|
|
* **User count**: 1
|
|
|
|
* **Monthly spending**: 0
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"company_created",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_contact_added_email(self) -> None:
|
|
|
|
expected_topic = "Contact: Azure Bus from St. John's"
|
|
|
|
expected_message = "New email jerryguitarist@gmail.com added to contact."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"contact_added_email",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_contact_created(self) -> None:
|
|
|
|
expected_topic = "Contact: Azure Bus from St. John's"
|
|
|
|
expected_message = """
|
|
|
|
New contact created:
|
|
|
|
* **Name (or pseudonym)**: Azure Bus from St. John's
|
|
|
|
* **Email**: aaron@zulip.com
|
|
|
|
* **Location**: St. John's, Newfoundland and Labrador, Canada
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"contact_created",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_contact_signed_up(self) -> None:
|
|
|
|
expected_topic = "User: Lilac Raindrop from St. John's"
|
|
|
|
expected_message = """
|
|
|
|
Contact signed up:
|
|
|
|
* **Email**: iago@zulip.com
|
|
|
|
* **Location**: St. John's, Newfoundland and Labrador, Canada
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"contact_signed_up",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_contact_tag_created(self) -> None:
|
|
|
|
expected_topic = "Contact: Eeshan Garg"
|
|
|
|
expected_message = "Contact tagged with the `developer` tag."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"contact_tag_created",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_contact_tag_deleted(self) -> None:
|
|
|
|
expected_topic = "Contact: Eeshan Garg"
|
|
|
|
expected_message = "The tag `developer` was removed from the contact."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"contact_tag_deleted",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_admin_assigned(self) -> None:
|
|
|
|
expected_topic = "Lead: Eeshan Garg"
|
|
|
|
expected_message = "Tim Abbott assigned to conversation."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_admin_assigned",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_admin_opened(self) -> None:
|
2021-04-11 16:26:54 +02:00
|
|
|
expected_topic = "Lead: Cordelia, Lear's daughter"
|
2019-03-28 21:32:28 +01:00
|
|
|
expected_message = "Eeshan Garg opened the conversation."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_admin_opened",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_admin_closed(self) -> None:
|
|
|
|
expected_topic = "Lead: Eeshan Garg"
|
2021-04-11 16:26:54 +02:00
|
|
|
expected_message = "Cordelia, Lear's daughter closed the conversation."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_admin_closed",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_admin_snoozed(self) -> None:
|
|
|
|
expected_topic = "Lead: Eeshan Garg"
|
2021-04-11 16:26:54 +02:00
|
|
|
expected_message = "Cordelia, Lear's daughter snoozed the conversation."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_admin_snoozed",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_admin_unsnoozed(self) -> None:
|
|
|
|
expected_topic = "Lead: Eeshan Garg"
|
2021-04-11 16:26:54 +02:00
|
|
|
expected_message = "Cordelia, Lear's daughter unsnoozed the conversation."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_admin_unsnoozed",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_admin_replied(self) -> None:
|
|
|
|
expected_topic = "Lead: Eeshan Garg"
|
|
|
|
expected_message = """
|
2021-04-11 16:26:54 +02:00
|
|
|
Cordelia, Lear's daughter replied to the conversation:
|
2019-03-28 21:32:28 +01:00
|
|
|
|
|
|
|
``` quote
|
|
|
|
Hey Eeshan! How can I help?
|
|
|
|
```
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_admin_replied",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_admin_noted(self) -> None:
|
|
|
|
expected_topic = "Lead: Eeshan Garg"
|
|
|
|
expected_message = """
|
2021-04-11 16:26:54 +02:00
|
|
|
Cordelia, Lear's daughter added a note to the conversation:
|
2019-03-28 21:32:28 +01:00
|
|
|
|
|
|
|
``` quote
|
|
|
|
Talk to Tim about this user's query.
|
|
|
|
```
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_admin_noted",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_admin_single_created(self) -> None:
|
|
|
|
expected_topic = "Lead: Eeshan Garg"
|
|
|
|
expected_message = """
|
2021-04-11 16:26:54 +02:00
|
|
|
Cordelia, Lear's daughter initiated a conversation:
|
2019-03-28 21:32:28 +01:00
|
|
|
|
|
|
|
``` quote
|
|
|
|
Hi Eeshan, What's up
|
|
|
|
```
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_admin_single_created",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_user_created(self) -> None:
|
|
|
|
expected_topic = "Lead: Rose Poodle from St. John's"
|
|
|
|
expected_message = """
|
|
|
|
Rose Poodle from St. John's initiated a conversation:
|
|
|
|
|
|
|
|
``` quote
|
|
|
|
Hello everyone!
|
|
|
|
```
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_user_created",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_conversation_user_replied(self) -> None:
|
|
|
|
expected_topic = "Lead: Eeshan Garg"
|
|
|
|
expected_message = """
|
|
|
|
Eeshan Garg replied to the conversation:
|
|
|
|
|
|
|
|
``` quote
|
|
|
|
Well, I need some help getting access to a developer account.
|
|
|
|
```
|
|
|
|
""".strip()
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"conversation_user_replied",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_event_created(self) -> None:
|
|
|
|
expected_topic = "Events"
|
|
|
|
expected_message = "New event **invited-friend** created."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"event_created",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_user_created(self) -> None:
|
|
|
|
expected_topic = "User: Aaron Smith"
|
|
|
|
expected_message = """
|
|
|
|
New user created:
|
|
|
|
* **Name**: Aaron Smith
|
|
|
|
* **Email**: aaron@zulip.com
|
|
|
|
""".strip()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"user_created",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_user_deleted(self) -> None:
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"user_deleted",
|
|
|
|
"User: jerryguitarist@gmail.com",
|
|
|
|
"User deleted.",
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_user_email_updated(self) -> None:
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"user_email_updated",
|
|
|
|
"Contact: Azure Bus from St. John's",
|
|
|
|
"User's email was updated to aaron@zulip.com.",
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_user_tag_created(self) -> None:
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"user_tag_created",
|
|
|
|
"User: eeshangarg",
|
|
|
|
"The tag `developer` was added to the user.",
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_user_tag_deleted(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
expected_topic = "User: eeshangarg"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
2021-02-12 08:20:45 +01:00
|
|
|
"The tag `CSV Import - 2019-03-26 22:46:04 UTC` was removed from the user."
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2019-03-28 21:32:28 +01:00
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"user_tag_deleted",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|
2018-01-06 12:11:44 +01:00
|
|
|
|
2019-03-28 21:32:28 +01:00
|
|
|
def test_user_unsubscribed(self) -> None:
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"user_unsubscribed",
|
|
|
|
"Contact: Eeshan Garg",
|
|
|
|
"User unsubscribed from emails.",
|
2019-03-28 21:32:28 +01:00
|
|
|
)
|