2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-20 22:04:21 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
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
|
2018-02-21 04:01:52 -05:00
|
|
|
count = serialized_for_user(admin).keys.count
|
2019-10-01 21:41:33 -04:00
|
|
|
difference = count - 38
|
2017-04-20 22:04:21 -04:00
|
|
|
|
|
|
|
expect(difference).to eq(0), lambda {
|
2019-05-06 03:16:22 -04:00
|
|
|
message = +""
|
2017-04-20 22:04:21 -04:00
|
|
|
|
|
|
|
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
|
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
|