A platform for community discussion. Free, open, simple.
FIX: Broken ping event for web hooks due to missing payload.
Guo Xiang Tan43f7cb05c97b
diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rbindex 4a968513670..db90dd04019 100644--- a/app/jobs/regular/emit_web_hook_event.rb+++ b/app/jobs/regular/emit_web_hook_event.rb@@ -8,7 +8,6 @@ module Jobs%i{web_hook_idevent_type- payload}.each do |key|raise Discourse::InvalidParameters.new(key) unless args[key].present?end@@ -25,6 +24,7 @@ module Jobsreturn 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])enddiff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rbindex 7354d78b94b..97a86f66838 100644--- a/spec/jobs/emit_web_hook_event_spec.rb+++ b/spec/jobs/emit_web_hook_event_spec.rb@@ -24,6 +24,16 @@ describe Jobs::EmitWebHookEvent doend.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" dosubject.execute(web_hook_id: inactive_hook.id,@@ -99,7 +109,7 @@ describe Jobs::EmitWebHookEvent doweb_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