2020-05-26 07:16:25 +02:00
|
|
|
from unittest.mock import MagicMock, patch
|
2018-10-20 03:19:31 +02:00
|
|
|
|
2016-12-24 15:50:46 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2016-12-24 15:50:46 +01:00
|
|
|
class GreenhouseHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "greenhouse"
|
2016-12-24 15:50:46 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/greenhouse?stream={stream}&api_key={api_key}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "greenhouse"
|
2016-12-24 15:50:46 +01:00
|
|
|
CONTENT_TYPE = "application/x-www-form-urlencoded"
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_message_candidate_hired(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Hire Candidate - 19"
|
2019-04-17 21:26:20 +02:00
|
|
|
expected_message = """
|
|
|
|
Hire Candidate Johnny Smith (ID: 19), applying for:
|
|
|
|
* **Role**: Developer
|
|
|
|
* **Emails**: personal@example.com (Personal), work@example.com (Work)
|
|
|
|
* **Attachments**: [Resume](https://prod-heroku.s3.amazonaws.com/...)
|
|
|
|
""".strip()
|
2016-12-24 15:50:46 +01:00
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"candidate_hired", expected_topic_name, expected_message, content_type=self.CONTENT_TYPE
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|
2016-12-24 15:50:46 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_message_candidate_rejected(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Reject Candidate - 265788"
|
2019-04-17 21:26:20 +02:00
|
|
|
expected_message = """
|
|
|
|
Reject Candidate Hector Porter (ID: 265788), applying for:
|
|
|
|
* **Role**: Designer
|
|
|
|
* **Emails**: hector.porter.265788@example.com (Personal)
|
|
|
|
* **Attachments**: [Resume](https://prod-heroku.s3.amazonaws.com/...)
|
|
|
|
""".strip()
|
2016-12-24 15:50:46 +01:00
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"candidate_rejected",
|
|
|
|
expected_topic_name,
|
|
|
|
expected_message,
|
|
|
|
content_type=self.CONTENT_TYPE,
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|
2016-12-24 15:50:46 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_message_candidate_stage_change(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Candidate Stage Change - 265772"
|
2019-04-17 21:26:20 +02:00
|
|
|
expected_message = """
|
|
|
|
Candidate Stage Change Giuseppe Hurley (ID: 265772), applying for:
|
|
|
|
* **Role**: Designer
|
|
|
|
* **Emails**: giuseppe.hurley@example.com (Personal)
|
|
|
|
* **Attachments**: [Resume](https://prod-heroku.s3.amazonaws.com/...), [Cover_Letter](https://prod-heroku.s3.amazonaws.com/...), [Attachment](https://prod-heroku.s3.amazonaws.com/...)
|
|
|
|
""".strip()
|
2016-12-24 15:50:46 +01:00
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"candidate_stage_change",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type=self.CONTENT_TYPE,
|
|
|
|
)
|
2016-12-24 15:50:46 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_message_prospect_created(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "New Prospect Application - 968190"
|
2019-04-17 21:26:20 +02:00
|
|
|
expected_message = """
|
|
|
|
New Prospect Application Trisha Troy (ID: 968190), applying for:
|
|
|
|
* **Role**: Designer
|
|
|
|
* **Emails**: t.troy@example.com (Personal)
|
|
|
|
* **Attachments**: [Resume](https://prod-heroku.s3.amazonaws.com/...)
|
|
|
|
""".strip()
|
2016-12-24 15:50:46 +01:00
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"prospect_created",
|
|
|
|
expected_topic_name,
|
|
|
|
expected_message,
|
|
|
|
content_type=self.CONTENT_TYPE,
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|
2016-12-24 15:50:46 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
@patch("zerver.webhooks.greenhouse.view.check_send_webhook_message")
|
2021-02-12 08:19:30 +01:00
|
|
|
def test_ping_message_ignore(self, check_send_webhook_message_mock: MagicMock) -> None:
|
2018-10-20 03:19:31 +02:00
|
|
|
self.url = self.build_webhook_url()
|
2021-02-12 08:20:45 +01:00
|
|
|
payload = self.get_body("ping_event")
|
2018-10-20 03:19:31 +02:00
|
|
|
result = self.client_post(self.url, payload, content_type=self.CONTENT_TYPE)
|
|
|
|
self.assertFalse(check_send_webhook_message_mock.called)
|
|
|
|
self.assert_json_success(result)
|