discourse/spec/serializers/web_hook_post_serializer_spec.rb
Blake Erickson 1ce6ff0a55 DEV: Include raw in post webhook serializer
This came in as a request on meta to include the raw field in the post
webhook serializer.

 https://meta.discourse.org/t/-/49045/55?u=blake

 Including this field can prevent needing to make a 2nd API request to
 get the raw field of a post.

 It would be handy down the road if we updated the webhook ui to specify
 fields or arguments that you wanted to be included in the serialized
 data, but most requests I've seen to update the serializers have been
 valid requests that are good to add anyways, so I don't think we have
 reached that point yet.
2020-06-10 11:56:39 -06:00

44 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe WebHookPostSerializer do
fab!(:admin) { Fabricate(:admin) }
fab!(:post) { Fabricate(: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
count = serialized_for_user(admin).keys.count
difference = count - 40
expect(difference).to eq(0), lambda {
message = +""
if difference < 0
message << "#{difference * -1} key(s) have been removed from this serializer."
else
message << "#{difference} key(s) have been added to this serializer."
end
message << "\nPlease verify if those key(s) are required as part of the web hook's payload."
}
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