2022-06-13 14:54:01 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe TopicTrackingStateSerializer do
|
2022-06-13 14:54:01 +08:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:post) { create_post }
|
|
|
|
|
2023-02-01 07:18:45 +08:00
|
|
|
it "serializes topic tracking state report correctly for a normal user" do
|
2022-06-13 14:54:01 +08:00
|
|
|
report = TopicTrackingState.report(user)
|
2023-02-01 07:18:45 +08:00
|
|
|
serialized = described_class.new(report, scope: Guardian.new(user), root: false).as_json
|
|
|
|
|
|
|
|
expect(serialized[:data].length).to eq(1)
|
|
|
|
expect(serialized[:data].first[:topic_id]).to eq(post.topic_id)
|
|
|
|
|
|
|
|
expect(serialized[:meta].keys).to contain_exactly(
|
|
|
|
TopicTrackingState::LATEST_MESSAGE_BUS_CHANNEL,
|
|
|
|
TopicTrackingState::RECOVER_MESSAGE_BUS_CHANNEL,
|
|
|
|
TopicTrackingState::DELETE_MESSAGE_BUS_CHANNEL,
|
|
|
|
TopicTrackingState::DESTROY_MESSAGE_BUS_CHANNEL,
|
|
|
|
TopicTrackingState::NEW_MESSAGE_BUS_CHANNEL,
|
|
|
|
TopicTrackingState::UNREAD_MESSAGE_BUS_CHANNEL,
|
|
|
|
TopicTrackingState.unread_channel_key(user.id),
|
2022-06-13 14:54:01 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|