mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 08:23:43 +08:00
FIX: Serialize an empty array if no suggested topics exist (#10134)
It used to return nil, which was ambiguous (empty vs absent result).
This commit is contained in:
parent
8fbc41d993
commit
1f6f1604c9
|
@ -7,11 +7,11 @@ module SuggestedTopicsMixin
|
|||
end
|
||||
|
||||
def include_related_messages?
|
||||
object.next_page.nil? && object.related_messages&.topics.present?
|
||||
object.next_page.nil? && object.related_messages&.topics
|
||||
end
|
||||
|
||||
def include_suggested_topics?
|
||||
object.next_page.nil? && object.suggested_topics&.topics.present?
|
||||
object.next_page.nil? && object.suggested_topics&.topics
|
||||
end
|
||||
|
||||
def related_messages
|
||||
|
|
|
@ -118,6 +118,40 @@ describe TopicViewSerializer do
|
|||
expect(json[:suggested_topics]).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with private messages' do
|
||||
let!(:topic) do
|
||||
Fabricate(:private_message_topic,
|
||||
highest_post_number: 1,
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: user)
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
let!(:topic2) do
|
||||
Fabricate(:private_message_topic,
|
||||
highest_post_number: 1,
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: user)
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
it 'includes suggested topics' do
|
||||
TopicUser.change(user, topic2.id, notification_level: TopicUser.notification_levels[:tracking])
|
||||
|
||||
json = serialize_topic(topic, user)
|
||||
expect(json[:suggested_topics].map { |t| t[:id] }).to contain_exactly(topic2.id)
|
||||
end
|
||||
|
||||
it 'does not include suggested topics if all PMs are read' do
|
||||
TopicUser.update_last_read(user, topic2.id, 1, 1, 0)
|
||||
|
||||
json = serialize_topic(topic, user)
|
||||
expect(json[:suggested_topics]).to eq([])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when tags added to private message topics' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user