2022-06-13 02:54:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe TopicTrackingStateSerializer do
|
2022-06-13 02:54:01 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:post) { create_post }
|
|
|
|
|
2023-01-31 18:18:45 -05:00
|
|
|
it "serializes topic tracking state report correctly for a normal user" do
|
2022-06-13 02:54:01 -04:00
|
|
|
report = TopicTrackingState.report(user)
|
2023-01-31 18:18:45 -05: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 02:54:01 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|