Skip to content

Commit

Permalink
feat(notification): add missing subscriber IDs for search
Browse files Browse the repository at this point in the history
  • Loading branch information
ryshu authored and unicodeveloper committed Feb 26, 2024
1 parent adeb5a5 commit 74218b0
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 132 deletions.
44 changes: 27 additions & 17 deletions novu/api/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def list(
channels: Optional[List[str]] = None,
templates: Optional[List[str]] = None,
emails: Optional[List[str]] = None,
subscriber_ids: Optional[List[str]] = None,
search: Optional[str] = None,
page: Optional[int] = 0,
transaction_id: Optional[str] = None,
Expand All @@ -41,31 +42,35 @@ def list(
Args:
channels: A required parameter, should be an array of strings representing
available notification channels, such as "in_app", "email", "sms",
"chat", and "push".
available notification channels, such as "in_app", "email", "sms",
"chat", and "push".
templates: A required parameter, should be an array of strings representing
the notification templates.
the notification templates.
emails: A required parameter, should be an array of strings representing
the email addresses associated with the notification.
the email addresses associated with the notification.
subscriber_ids: An array of subscriber's identifier associated with searched
notifications.
search: A required parameter, should be a string representing the search query.
page: An optional parameter with a default value of 0, representing the page
number for search results.
number for search results.
transaction_id: A required parameter, should be a string representing the
transaction ID associated with the notification.
transaction ID associated with the notification.
Returns:
Gets notifications in Novu
"""
payload = {
"channels": channels,
"templates": templates,
"emails": emails,
"channels": channels or [],
"templates": templates or [],
"emails": emails or [],
"subscriberIds": subscriber_ids or [],
"search": search,
"page": page,
"transactionId": transaction_id,
Expand All @@ -79,34 +84,39 @@ def stream(
channels: Optional[List[str]] = None,
templates: Optional[List[str]] = None,
emails: Optional[List[str]] = None,
subscriber_ids: Optional[List[str]] = None,
search: Optional[str] = None,
transaction_id: Optional[str] = None,
) -> PaginationIterator[ActivityNotificationDto]:
"""Stream all existing notifications into an iterator.
Args:
channels: A required parameter, should be an array of strings representing
available notification channels, such as "in_app", "email", "sms",
"chat", and "push".
available notification channels, such as "in_app", "email", "sms",
"chat", and "push".
templates: A required parameter, should be an array of strings representing
the notification templates.
the notification templates.
emails: A required parameter, should be an array of strings representing
the email addresses associated with the notification.
the email addresses associated with the notification.
subscriber_ids: An array of subscriber's identifier associated with searched
notifications.
search: A required parameter, should be a string representing the search query.
transaction_id: A required parameter, should be a string representing the
transaction ID associated with the notification.
transaction ID associated with the notification.
Returns:
An iterator on all notifications available.
"""
payload = {
"channels": channels,
"templates": templates,
"emails": emails,
"channels": channels or [],
"templates": templates or [],
"emails": emails or [],
"subscriberIds": subscriber_ids or [],
"search": search,
"transactionId": transaction_id,
}
Expand Down
241 changes: 126 additions & 115 deletions tests/api/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,126 +22,129 @@


class NotificationApiTests(TestCase):
@classmethod
def setUpClass(cls) -> None:
NovuConfig.configure("sample.novu.com", "api-key")
cls.api = NotificationApi()
cls.notification_json = {
"_id": "63dafed97779f59258e44954",
"_environmentId": "63dafed97779f59258e38445",
"_organizationId": "789er454569345",
"transactionId": "fefrey56v",
"createdAt": "2023-07-13",
"channels": ["in_app"],
"subscriber": {
"firstName": "Max",
"_id": "123",
"lastName": "Moe",
"email": "max.moe@example.com",
"phone": "+441234567893",
},
"template": {
"_id": "12crefr3",
"name": "Template3",
"triggers": [
api: NotificationApi

notification_json = {
"_id": "63dafed97779f59258e44954",
"_environmentId": "63dafed97779f59258e38445",
"_organizationId": "789er454569345",
"transactionId": "fefrey56v",
"createdAt": "2023-07-13",
"channels": ["in_app"],
"subscriber": {
"firstName": "Max",
"_id": "123",
"lastName": "Moe",
"email": "max.moe@example.com",
"phone": "+441234567893",
},
"template": {
"_id": "12crefr3",
"name": "Template3",
"triggers": [
{
"type": "type1",
"identifier": "identifier1",
"variables": [{"name": "variable4"}],
"subscriberVariables": [{"name": "subscribeVariable1"}],
}
],
},
"jobs": [
{
"_id": "123vivie3",
"type": "Type1",
"digest": {},
"executionDetails": [
{
"type": "type1",
"identifier": "identifier1",
"variables": [{"name": "variable4"}],
"subscriberVariables": [{"name": "subscribeVariable1"}],
"_id": "123",
"_jobId": "456",
"status": "Success",
"detail": "Detail",
"isRetry": True,
"isTest": False,
"providerId": {},
"raw": "Raw",
"source": "Credentials",
}
],
},
"jobs": [
{
"_id": "123vivie3",
"type": "Type1",
"digest": {},
"executionDetails": [
{
"_id": "123",
"_jobId": "456",
"status": "Success",
"detail": "Detail",
"isRetry": True,
"isTest": False,
"providerId": {},
"raw": "Raw",
"source": "Credentials",
}
],
"step": {
"_id": "123",
"active": True,
"filters": {},
"template": {},
},
"payload": {},
"providerId": {},
"status": "completed",
"step": {
"_id": "123",
"active": True,
"filters": {},
"template": {},
},
"payload": {},
"providerId": {},
"status": "completed",
},
],
}
response_notification = {"data": notification_json}
response_list = {"page": 0, "hasMore": False, "pageSize": 10, "data": [notification_json]}
expected_dto = ActivityNotificationDto(
_id="63dafed97779f59258e44954",
_environment_id="63dafed97779f59258e38445",
_organization_id="789er454569345",
transaction_id="fefrey56v",
created_at="2023-07-13",
channels=["in_app"],
subscriber=ActivityNotificationSubscriberResponseDTO(
first_name="Max",
_id="123",
last_name="Moe",
email="max.moe@example.com",
phone="+441234567893",
),
template=ActivityNotificationTemplateResponseDto(
_id="12crefr3",
name="Template3",
triggers=[
ActivityNotificationTriggerResponseDto(
type="type1",
identifier="identifier1",
variables=[{"name": "variable4"}],
subscriber_variables=[{"name": "subscriberVariable1"}],
),
],
}
cls.response_notification = {"data": cls.notification_json}
cls.response_list = {"page": 0, "hasMore": False, "pageSize": 10, "data": [cls.notification_json]}
cls.expected_dto = ActivityNotificationDto(
_id="63dafed97779f59258e44954",
_environment_id="63dafed97779f59258e38445",
_organization_id="789er454569345",
transaction_id="fefrey56v",
created_at="2023-07-13",
channels=["in_app"],
subscriber=ActivityNotificationSubscriberResponseDTO(
first_name="Max",
_id="123",
last_name="Moe",
email="max.moe@example.com",
phone="+441234567893",
),
template=ActivityNotificationTemplateResponseDto(
_id="12crefr3",
name="Template3",
triggers=[
ActivityNotificationTriggerResponseDto(
type="type1",
identifier="identifier1",
variables=[{"name": "variable4"}],
subscriber_variables=[{"name": "subscriberVariable1"}],
),
jobs=[
ActivityNotificationJobResponseDto(
_id="123vivie3",
type="Type1",
digest={},
execution_details=[
ActivityNotificationExecutionDetailResponseDto(
_id="123",
_job_id="456",
status="Success",
detail="Detail",
is_retry=True,
is_test=False,
provider_id={},
raw="Raw",
source="Credentials",
)
],
step=[
ActivityNotificationStepResponseDto(
_id="123",
active=True,
filters={},
template={},
),
],
),
jobs=[
ActivityNotificationJobResponseDto(
_id="123vivie3",
type="Type1",
digest={},
execution_details=[
ActivityNotificationExecutionDetailResponseDto(
_id="123",
_job_id="456",
status="Success",
detail="Detail",
is_retry=True,
is_test=False,
provider_id={},
raw="Raw",
source="Credentials",
)
],
step=[
ActivityNotificationStepResponseDto(
_id="123",
active=True,
filters={},
template={},
),
],
payload={},
provider_id={},
status="completed",
)
],
)
payload={},
provider_id={},
status="completed",
)
],
)

@classmethod
def setUpClass(cls) -> None:
NovuConfig.configure("sample.novu.com", "api-key")
cls.api = NotificationApi()

@mock.patch("requests.request")
def test_list(self, mock_request: mock.MagicMock) -> None:
Expand All @@ -150,8 +153,11 @@ def test_list(self, mock_request: mock.MagicMock) -> None:
channels = ["in_app"]
templates = ["Template3"]
emails = ["max.moe@example.com"]
subscriber_ids = ["johndoe"]
search = "example"
result = self.api.list(channels, templates, emails, search)
result = self.api.list(
channels=channels, templates=templates, emails=emails, subscriber_ids=subscriber_ids, search=search
)

self.assertIsInstance(result, PaginatedActivityNotificationDto)
notification_result = result.data[0]
Expand All @@ -168,6 +174,7 @@ def test_list(self, mock_request: mock.MagicMock) -> None:
"channels": channels,
"templates": templates,
"emails": emails,
"subscriberIds": subscriber_ids,
"search": search,
"page": 0,
"transactionId": None,
Expand All @@ -182,8 +189,11 @@ def test_stream(self, mock_request: mock.MagicMock) -> None:
channels = ["in_app"]
templates = ["Template3"]
emails = ["max.moe@example.com"]
subscriber_ids = ["johndoe"]
search = "example"
result = self.api.stream(channels, templates, emails, search)
result = self.api.stream(
channels=channels, templates=templates, emails=emails, subscriber_ids=subscriber_ids, search=search
)

self.assertIsInstance(result, PaginationIterator)
notification_result = next(result)
Expand All @@ -200,6 +210,7 @@ def test_stream(self, mock_request: mock.MagicMock) -> None:
"channels": channels,
"templates": templates,
"emails": emails,
"subscriberIds": subscriber_ids,
"search": search,
"page": 0,
"limit": 10,
Expand Down

0 comments on commit 74218b0

Please sign in to comment.