FIX: Broken ping event for web hooks due to missing payload.

This commit is contained in:
Guo Xiang Tan 2018-05-24 15:16:52 +08:00
parent b3860c82da
commit 43f7cb05c9
2 changed files with 12 additions and 2 deletions

View File

@ -8,7 +8,6 @@ module Jobs
%i{
web_hook_id
event_type
payload
}.each do |key|
raise Discourse::InvalidParameters.new(key) unless args[key].present?
end
@ -25,6 +24,7 @@ module Jobs
return if web_hook.category_ids.present? && (!args[:category_id].present? ||
!web_hook.category_ids.include?(args[:category_id]))
raise Discourse::InvalidParameters.new(:payload) unless args[:payload].present?
args[:payload] = JSON.parse(args[:payload])
end

View File

@ -24,6 +24,16 @@ describe Jobs::EmitWebHookEvent do
end.to raise_error(Discourse::InvalidParameters)
end
it 'does not raise an error for a ping event without payload' do
stub_request(:post, "https://meta.discourse.org/webhook_listener")
.to_return(body: 'OK', status: 200)
subject.execute(
web_hook_id: post_hook.id,
event_type: described_class::PING_EVENT
)
end
it "doesn't emit when the hook is inactive" do
subject.execute(
web_hook_id: inactive_hook.id,
@ -99,7 +109,7 @@ describe Jobs::EmitWebHookEvent do
web_hook_id: post_hook.id,
event_type: described_class::PING_EVENT,
event_name: described_class::PING_EVENT,
payload: { test: "some payload" }.to_json
payload: { test: "this payload shouldn't appear" }.to_json
)
event = WebHookEvent.last