Skip to content

Commit f994b8c

Browse files
committed
Adding fixtures for notification test to bring parity with Ruby library.
1 parent 7e1fc58 commit f994b8c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

intercom/lib/typed_json_deserializer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def deserialize(self):
3232
return self.deserialize_object(self._json)
3333

3434
def deserialize_collection(self, collection_json):
35+
if collection_json is None:
36+
return []
3537
return [JsonDeserializer(object_json).deserialize()
3638
for object_json in collection_json]
3739

tests/unit/notification_spec.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ def it_returns_correct_user_notification_topic(self):
2222
payload = Notification(**test_user_notification)
2323
expect(payload.topic) == "user.created"
2424

25+
def it_returns_instance_of_user(self):
26+
User = create_class_instance('User') # noqa
27+
payload = Notification(**test_user_notification)
28+
expect(payload.model).to.be_instance_of(User.__class__)
29+
2530
def it_returns_instance_of_conversation(self):
2631
Conversation = create_class_instance('Conversation')
2732
payload = Notification(**test_conversation_notification)
2833
expect(payload.model).to.be_instance_of(Conversation.__class__)
34+
35+
def it_returns_correct_model_type_for_conversation(self):
36+
Conversation = create_class_instance('Conversation')
37+
payload = Notification(**test_conversation_notification)
2938
expect(payload.model_type) == Conversation.__class__
3039

3140
def it_returns_correct_conversation_notification_topic(self):
@@ -36,3 +45,25 @@ def it_returns_inner_user_object_for_conversation(self):
3645
User = create_class_instance('User')
3746
payload = Notification(**test_conversation_notification)
3847
expect(payload.model.user).to.be_instance_of(User.__class__)
48+
49+
def it_returns_inner_user_object_with_nil_tags(self):
50+
user_notification = {
51+
"type": "notification_event",
52+
"app_id": "aa11aa",
53+
"data": {
54+
"type": "notification_event_data",
55+
"item": {
56+
"type": "user",
57+
"id": "abc123def",
58+
"user_id": "666",
59+
"email": "joe@example.com",
60+
"name": "Joe",
61+
"tags": {
62+
"type": "tag.list",
63+
"tags": None
64+
}
65+
}
66+
}
67+
}
68+
payload = Notification(**user_notification)
69+
expect(payload.model.tags) == []

0 commit comments

Comments
 (0)