Skip to content

Commit 49eb7c8

Browse files
committed
deal with nils in collection lists
1 parent 8e89968 commit 49eb7c8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/intercom/lib/typed_json_deserializer.rb

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def list_object_type?(object_type)
3131
end
3232

3333
def deserialize_collection(collection_json)
34+
return [] if collection_json == nil
3435
collection_json.map { |item_json| TypedJsonDeserializer.new(item_json).deserialize }
3536
end
3637

spec/unit/intercom/notification_spec.rb

+24-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,28 @@
4141
payload = Intercom::Notification.new(test_conversation_notification)
4242
payload.model.user.must_be_instance_of Intercom::User
4343
end
44+
45+
it "returns inner User object with nil tags" do
46+
user_notification = {
47+
"type" => "notification_event",
48+
"app_id" => "aa11aa",
49+
"data" => {
50+
"type" => "notification_event_data",
51+
"item" => {
52+
"type" => "user",
53+
"id" => "abc123def",
54+
"user_id" => "666",
55+
"email" => "[email protected]",
56+
"name" => "Joe",
57+
"tags" => {
58+
"type" => "tag.list",
59+
"tags" => nil
60+
}
61+
}
62+
},
63+
}
64+
payload = Intercom::Notification.new(user_notification)
65+
payload.model.tags.must_equal([])
66+
end
4467

45-
end
68+
end

0 commit comments

Comments
 (0)