2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe TopicViewPostsSerializer do
|
2019-06-07 16:12:30 +08:00
|
|
|
|
2021-11-24 23:28:20 +08:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
let(:topic) { post.topic }
|
|
|
|
let!(:reviewable) { Fabricate(:reviewable_flagged_post,
|
|
|
|
created_by: user,
|
|
|
|
target: post,
|
|
|
|
topic: topic,
|
|
|
|
reviewable_scores: [
|
|
|
|
Fabricate(:reviewable_score, reviewable_score_type: 0, status: ReviewableScore.statuses[:pending]),
|
|
|
|
Fabricate(:reviewable_score, reviewable_score_type: 0, status: ReviewableScore.statuses[:ignored])
|
|
|
|
]
|
|
|
|
)}
|
2019-06-07 16:12:30 +08:00
|
|
|
|
2021-11-24 23:28:20 +08:00
|
|
|
it 'should return the right attributes' do
|
2019-06-07 16:12:30 +08:00
|
|
|
topic_view = TopicView.new(topic, user, post_ids: [post.id])
|
|
|
|
|
|
|
|
serializer = TopicViewPostsSerializer.new(
|
|
|
|
topic_view,
|
2018-06-22 10:38:31 +08:00
|
|
|
scope: Guardian.new(Fabricate(:admin)),
|
|
|
|
root: false
|
|
|
|
)
|
|
|
|
|
2019-06-07 16:12:30 +08:00
|
|
|
body = JSON.parse(serializer.to_json)
|
2018-06-22 10:38:31 +08:00
|
|
|
|
|
|
|
posts = body["post_stream"]["posts"]
|
|
|
|
|
|
|
|
expect(posts.count).to eq(1)
|
|
|
|
expect(posts.first["id"]).to eq(post.id)
|
2019-06-07 16:12:30 +08:00
|
|
|
|
|
|
|
expect(posts.first["reviewable_score_count"]).to eq(2)
|
|
|
|
expect(posts.first["reviewable_score_pending_count"]).to eq(1)
|
|
|
|
|
2018-06-22 10:38:31 +08:00
|
|
|
expect(body["post_stream"]["stream"]).to eq(nil)
|
|
|
|
expect(body["post_stream"]["timeline_lookup"]).to eq(nil)
|
2018-07-02 13:58:02 +08:00
|
|
|
expect(body["post_stream"]["gaps"]).to eq(nil)
|
2019-06-07 16:12:30 +08:00
|
|
|
|
2018-06-22 10:38:31 +08:00
|
|
|
end
|
|
|
|
end
|