Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions mailersend/builders/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def activity_events(self) -> "WebhooksBuilder":
"activity.delivered",
"activity.soft_bounced",
"activity.hard_bounced",
"activity.deferred",
"activity.opened",
"activity.opened_unique",
"activity.clicked",
Expand Down Expand Up @@ -154,6 +155,20 @@ def system_events(self) -> "WebhooksBuilder":
self.add_event(event)
return self

def recipient_events(self) -> "WebhooksBuilder":
"""Add all recipient events to the webhook.

Returns:
WebhooksBuilder: Self for method chaining
"""
recipient_events = [
"recipient.on_hold_added",
"recipient.on_hold_removed",
]
for event in recipient_events:
self.add_event(event)
return self

def all_events(self) -> "WebhooksBuilder":
"""Add all available events to the webhook.

Expand All @@ -162,6 +177,7 @@ def all_events(self) -> "WebhooksBuilder":
"""
self.activity_events()
self.system_events()
self.recipient_events()
return self

def build_webhooks_list_request(self) -> WebhooksListRequest:
Expand Down
20 changes: 19 additions & 1 deletion tests/unit/test_webhooks_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def test_activity_events(self):
"activity.delivered",
"activity.soft_bounced",
"activity.hard_bounced",
"activity.deferred",
"activity.opened",
"activity.opened_unique",
"activity.clicked",
Expand Down Expand Up @@ -128,6 +129,18 @@ def test_system_events(self):
]
assert builder._events == expected_events

def test_recipient_events(self):
"""Test adding all recipient events."""
builder = WebhooksBuilder()
result = builder.recipient_events()
assert result is builder # Fluent interface

expected_events = [
"recipient.on_hold_added",
"recipient.on_hold_removed",
]
assert builder._events == expected_events

def test_all_events(self):
"""Test adding all available events."""
builder = WebhooksBuilder()
Expand All @@ -139,6 +152,7 @@ def test_all_events(self):
"activity.delivered",
"activity.soft_bounced",
"activity.hard_bounced",
"activity.deferred",
"activity.opened",
"activity.opened_unique",
"activity.clicked",
Expand All @@ -157,7 +171,11 @@ def test_all_events(self):
"email_list.verified",
"bulk_email.completed",
]
expected_all_events = expected_activity_events + expected_system_events
expected_recipient_events = [
"recipient.on_hold_added",
"recipient.on_hold_removed",
]
expected_all_events = expected_activity_events + expected_system_events + expected_recipient_events
assert builder._events == expected_all_events

def test_method_chaining(self):
Expand Down