2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-21 21:38:31 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2019-06-07 03:12:30 -05:00
|
|
|
describe TopicViewPostsSerializer do
|
|
|
|
|
|
|
|
it 'should return the right attributes' do
|
|
|
|
|
|
|
|
user = Fabricate(:user)
|
|
|
|
post = Fabricate(:post)
|
|
|
|
topic = post.topic
|
|
|
|
|
|
|
|
reviewable = Fabricate(:reviewable_flagged_post, created_by: user, target: post, topic: topic)
|
|
|
|
|
|
|
|
ReviewableScore.create!(
|
|
|
|
reviewable_id: reviewable.id,
|
|
|
|
user_id: user.id,
|
|
|
|
reviewable_score_type: 0,
|
|
|
|
status: ReviewableScore.statuses[:pending]
|
|
|
|
)
|
|
|
|
|
|
|
|
ReviewableScore.create!(
|
|
|
|
reviewable_id: reviewable.id,
|
|
|
|
user_id: user.id,
|
|
|
|
reviewable_score_type: 0,
|
|
|
|
status: ReviewableScore.statuses[:ignored]
|
|
|
|
)
|
|
|
|
|
|
|
|
topic_view = TopicView.new(topic, user, post_ids: [post.id])
|
|
|
|
|
|
|
|
serializer = TopicViewPostsSerializer.new(
|
|
|
|
topic_view,
|
2018-06-21 21:38:31 -05:00
|
|
|
scope: Guardian.new(Fabricate(:admin)),
|
|
|
|
root: false
|
|
|
|
)
|
|
|
|
|
2019-06-07 03:12:30 -05:00
|
|
|
body = JSON.parse(serializer.to_json)
|
2018-06-21 21:38:31 -05:00
|
|
|
|
|
|
|
posts = body["post_stream"]["posts"]
|
|
|
|
|
|
|
|
expect(posts.count).to eq(1)
|
|
|
|
expect(posts.first["id"]).to eq(post.id)
|
2019-06-07 03:12:30 -05:00
|
|
|
|
|
|
|
expect(posts.first["reviewable_score_count"]).to eq(2)
|
|
|
|
expect(posts.first["reviewable_score_pending_count"]).to eq(1)
|
|
|
|
|
2018-06-21 21:38:31 -05:00
|
|
|
expect(body["post_stream"]["stream"]).to eq(nil)
|
|
|
|
expect(body["post_stream"]["timeline_lookup"]).to eq(nil)
|
2018-07-02 00:58:02 -05:00
|
|
|
expect(body["post_stream"]["gaps"]).to eq(nil)
|
2019-06-07 03:12:30 -05:00
|
|
|
|
2018-06-21 21:38:31 -05:00
|
|
|
end
|
|
|
|
end
|