2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-20 22:04:21 -04:00
|
|
|
RSpec.describe WebHookPostSerializer do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
fab!(:post) { Fabricate(:post) }
|
2018-02-21 04:01:52 -05:00
|
|
|
|
|
|
|
def serialized_for_user(u)
|
|
|
|
WebHookPostSerializer.new(post, scope: Guardian.new(u), root: false).as_json
|
|
|
|
end
|
2017-04-20 22:04:21 -04:00
|
|
|
|
|
|
|
it "should only include the required keys" do
|
2021-07-08 03:46:21 -04:00
|
|
|
expect(serialized_for_user(admin).keys).to contain_exactly(
|
|
|
|
:id,
|
|
|
|
:name,
|
|
|
|
:username,
|
|
|
|
:avatar_template,
|
|
|
|
:created_at,
|
|
|
|
:cooked,
|
|
|
|
:post_number,
|
|
|
|
:post_type,
|
|
|
|
:updated_at,
|
|
|
|
:reply_count,
|
|
|
|
:reply_to_post_number,
|
|
|
|
:quote_count,
|
|
|
|
:incoming_link_count,
|
|
|
|
:reads,
|
|
|
|
:score,
|
|
|
|
:topic_id,
|
|
|
|
:topic_slug,
|
|
|
|
:topic_title,
|
|
|
|
:category_id,
|
|
|
|
:display_username,
|
|
|
|
:primary_group_name,
|
|
|
|
:flair_name,
|
2023-04-24 15:04:26 -04:00
|
|
|
:flair_group_id,
|
2021-07-08 03:46:21 -04:00
|
|
|
:version,
|
|
|
|
:user_title,
|
|
|
|
:bookmarked,
|
|
|
|
:raw,
|
|
|
|
:moderator,
|
|
|
|
:admin,
|
|
|
|
:staff,
|
|
|
|
:user_id,
|
|
|
|
:hidden,
|
|
|
|
:trust_level,
|
|
|
|
:deleted_at,
|
|
|
|
:user_deleted,
|
|
|
|
:edit_reason,
|
|
|
|
:wiki,
|
|
|
|
:reviewable_id,
|
|
|
|
:reviewable_score_count,
|
|
|
|
:reviewable_score_pending_count,
|
|
|
|
:topic_posts_count,
|
|
|
|
:topic_filtered_posts_count,
|
|
|
|
:topic_archetype,
|
|
|
|
:category_slug,
|
|
|
|
)
|
2017-04-20 22:04:21 -04:00
|
|
|
end
|
2018-02-21 04:01:52 -05:00
|
|
|
|
2020-09-02 10:42:51 -04:00
|
|
|
it "includes category_id" do
|
|
|
|
expect(serialized_for_user(admin)[:category_id]).to eq(post.topic.category_id)
|
|
|
|
end
|
|
|
|
|
2018-02-21 04:01:52 -05:00
|
|
|
it "should only include deleted topic title for staffs" do
|
|
|
|
topic = post.topic
|
|
|
|
PostDestroyer.new(Discourse.system_user, post).destroy
|
|
|
|
post.reload
|
|
|
|
|
|
|
|
[nil, post.user, Fabricate(:user)].each do |user|
|
|
|
|
expect(serialized_for_user(user)[:topic_title]).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
[Fabricate(:moderator), admin].each do |user|
|
|
|
|
expect(serialized_for_user(user)[:topic_title]).to eq(topic.title)
|
|
|
|
end
|
|
|
|
end
|
2017-04-20 22:04:21 -04:00
|
|
|
end
|