FIX: Correct highest post number for read topic tracking state. (#14273)

This commit is contained in:
Alan Guo Xiang Tan
2021-09-08 11:55:12 +08:00
committed by GitHub
parent e3793e6d7c
commit 5de64b3630
3 changed files with 58 additions and 5 deletions

View File

@ -40,6 +40,43 @@ describe TopicTrackingState do
end
end
describe '.publish_read' do
it 'correctly publish read' do
message = MessageBus.track_publish(described_class.unread_channel_key(post.user.id)) do
TopicTrackingState.publish_read(post.topic_id, 1, post.user)
end.first
data = message.data
expect(message.user_ids).to contain_exactly(post.user_id)
expect(message.group_ids).to eq(nil)
expect(data["topic_id"]).to eq(post.topic_id)
expect(data["message_type"]).to eq(described_class::READ_MESSAGE_TYPE)
expect(data["payload"]["last_read_post_number"]).to eq(1)
expect(data["payload"]["highest_post_number"]).to eq(1)
expect(data["payload"]["notification_level"]).to eq(nil)
end
it 'correctly publish read for staff' do
create_post(
raw: "this is a test post",
topic: post.topic,
post_type: Post.types[:whisper],
user: Fabricate(:admin)
)
post.user.grant_admin!
message = MessageBus.track_publish(described_class.unread_channel_key(post.user.id)) do
TopicTrackingState.publish_read(post.topic_id, 1, post.user)
end.first
data = message.data
expect(data["payload"]["highest_post_number"]).to eq(2)
end
end
describe '#publish_unread' do
it "can correctly publish unread" do
message = MessageBus.track_publish(described_class.unread_channel_key(post.user.id)) do