discourse/spec/serializers/web_hook_post_serializer_spec.rb
Keegan George 7b76d25946
DEV: Adopt post list component and new posts route front-end (#30604)
Recently we introduced a new `PostList` component (d886c55f63). In this update, we make broader adoption of this component. In particular, these areas include using the new component in the user activity stream pages, user's deleted posts, and pending posts page. This update also takes the existing `posts` route and adds a barebones front-end for it to view posts all in one page.

---------

Co-authored-by: David Taylor <david@taylorhq.com>
2025-01-23 10:20:45 -08:00

80 lines
1.8 KiB
Ruby

# frozen_string_literal: true
RSpec.describe WebHookPostSerializer do
fab!(:admin)
fab!(:post)
def serialized_for_user(u)
WebHookPostSerializer.new(post, scope: Guardian.new(u), root: false).as_json
end
it "should only include the required keys" do
expect(serialized_for_user(admin).keys).to contain_exactly(
:id,
:name,
:username,
:avatar_template,
:created_at,
:cooked,
:post_number,
:post_type,
:posts_count,
: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,
:flair_group_id,
: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,
:post_url,
:topic_posts_count,
:topic_filtered_posts_count,
:topic_archetype,
:category_slug,
)
end
it "includes category_id" do
expect(serialized_for_user(admin)[:category_id]).to eq(post.topic.category_id)
end
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
end