Skip to content

Commit

Permalink
feat(subscriber): add missing data field
Browse files Browse the repository at this point in the history
  • Loading branch information
ryshu authored and unicodeveloper committed Feb 26, 2024
1 parent 74218b0 commit 79678d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
16 changes: 15 additions & 1 deletion novu/dto/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,17 @@ class SubscriberChannelSettingsDto(CamelCaseDto["SubscriberChannelSettingsDto"])
class SubscriberDto(CamelCaseDto["SubscriberDto"]): # pylint: disable=R0902
"""Definition of subscriber"""

camel_case_fields = ["subscriber_id", "email", "first_name", "last_name", "phone", "avatar", "locale", "channels"]
camel_case_fields = [
"subscriber_id",
"email",
"first_name",
"last_name",
"phone",
"avatar",
"locale",
"channels",
"data",
]
# Actually, only these fields are editable in Novu, so prevent any activity on others

subscriber_id: str
Expand Down Expand Up @@ -161,6 +171,10 @@ class SubscriberDto(CamelCaseDto["SubscriberDto"]): # pylint: disable=R0902
last_online_at: Optional[str] = None
"""Last connection date of the subscriber"""

data: Optional[dict] = None
"""Apart from the above fixed structured user data, this field contain
any unstructured custom data such as user’s address, nationality, height, etc."""


@dataclasses.dataclass
class PaginatedSubscriberDto(CamelCaseDto["PaginatedSubscriberDto"]):
Expand Down
17 changes: 15 additions & 2 deletions tests/api/test_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def setUpClass(cls) -> None:
"__v": 0,
"isOnline": False,
"lastOnlineAt": "2023-02-06T23:03:22.645Z",
"data": None,
}
cls.response_list = {
"page": 0,
Expand All @@ -64,6 +65,7 @@ def setUpClass(cls) -> None:
updated_at="2023-02-06T23:03:22.645Z",
is_online=False,
last_online_at="2023-02-06T23:03:22.645Z",
data=None,
)

@mock.patch("requests.request")
Expand Down Expand Up @@ -139,6 +141,7 @@ def test_create_subscriber(self, mock_request: mock.MagicMock) -> None:
"updatedAt": "2023-02-07T22:10:57.433Z",
"__v": 0,
"id": "63e2cc7151af34c4b2f2b5d1",
"data": None,
}
},
)
Expand All @@ -161,6 +164,7 @@ def test_create_subscriber(self, mock_request: mock.MagicMock) -> None:
"avatar": None,
"locale": None,
"channels": None,
"data": None,
},
params=None,
timeout=5,
Expand Down Expand Up @@ -188,6 +192,7 @@ def test_bulk_create_subscribers(self, mock_request: mock.MagicMock) -> None:
"deleted": None,
"__v": 0,
"id": "63e2cc7151af34c4b2f2b5d1",
"data": {"test": "value"},
},
{
"_organizationId": None,
Expand All @@ -204,6 +209,7 @@ def test_bulk_create_subscribers(self, mock_request: mock.MagicMock) -> None:
"deleted": None,
"__v": 0,
"id": "63e2cc7151af34c4b2f2b5d2",
"data": {"test": "value"},
},
],
"updated": [],
Expand All @@ -213,8 +219,8 @@ def test_bulk_create_subscribers(self, mock_request: mock.MagicMock) -> None:
)

subscribers = [
SubscriberDto(subscriber_id="subscriber-id", email="subscriber@sample.com"),
SubscriberDto(subscriber_id="subscriber1-id", email="subscriber1@sample.com"),
SubscriberDto(subscriber_id="subscriber-id", email="subscriber@sample.com", data={"test": "value"}),
SubscriberDto(subscriber_id="subscriber1-id", email="subscriber1@sample.com", data={"test": "value"}),
]

res = self.api.bulk_create(subscribers)
Expand All @@ -229,12 +235,14 @@ def test_bulk_create_subscribers(self, mock_request: mock.MagicMock) -> None:
email="subscriber@sample.com",
_id="63e2cc7151af34c4b2f2b5d1",
channels=[],
data={"test": "value"},
),
SubscriberDto(
subscriber_id="subscriber1-id",
email="subscriber1@sample.com",
_id="63e2cc7151af34c4b2f2b5d2",
channels=[],
data={"test": "value"},
),
],
updated=[],
Expand All @@ -257,6 +265,7 @@ def test_bulk_create_subscribers(self, mock_request: mock.MagicMock) -> None:
"avatar": None,
"locale": None,
"channels": None,
"data": {"test": "value"},
},
{
"subscriberId": "subscriber1-id",
Expand All @@ -267,6 +276,7 @@ def test_bulk_create_subscribers(self, mock_request: mock.MagicMock) -> None:
"avatar": None,
"locale": None,
"channels": None,
"data": {"test": "value"},
},
]
},
Expand Down Expand Up @@ -336,6 +346,7 @@ def test_get_subscriber_with_credentials_info(self, mock_request: mock.MagicMock
"isOnline": False,
"email": "oscar.marie-taillefer@spikeelabs.fr",
"lastOnlineAt": "2023-02-06T23:03:22.645Z",
"data": None,
}
},
)
Expand Down Expand Up @@ -368,6 +379,7 @@ def test_get_subscriber_with_credentials_info(self, mock_request: mock.MagicMock
updated_at="2023-02-06T23:03:22.645Z",
is_online=False,
last_online_at="2023-02-06T23:03:22.645Z",
data=None,
),
)

Expand Down Expand Up @@ -402,6 +414,7 @@ def test_update_subscriber(self, mock_request: mock.MagicMock) -> None:
"avatar": None,
"locale": None,
"channels": None,
"data": None,
},
params=None,
timeout=5,
Expand Down

0 comments on commit 79678d6

Please sign in to comment.