mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: Broken ping event for web hooks due to missing payload.
This commit is contained in:
parent
b3860c82da
commit
43f7cb05c9
2 changed files with 12 additions and 2 deletions
|
@ -8,7 +8,6 @@ module Jobs
|
||||||
%i{
|
%i{
|
||||||
web_hook_id
|
web_hook_id
|
||||||
event_type
|
event_type
|
||||||
payload
|
|
||||||
}.each do |key|
|
}.each do |key|
|
||||||
raise Discourse::InvalidParameters.new(key) unless args[key].present?
|
raise Discourse::InvalidParameters.new(key) unless args[key].present?
|
||||||
end
|
end
|
||||||
|
@ -25,6 +24,7 @@ module Jobs
|
||||||
return if web_hook.category_ids.present? && (!args[:category_id].present? ||
|
return if web_hook.category_ids.present? && (!args[:category_id].present? ||
|
||||||
!web_hook.category_ids.include?(args[:category_id]))
|
!web_hook.category_ids.include?(args[:category_id]))
|
||||||
|
|
||||||
|
raise Discourse::InvalidParameters.new(:payload) unless args[:payload].present?
|
||||||
args[:payload] = JSON.parse(args[:payload])
|
args[:payload] = JSON.parse(args[:payload])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,16 @@ describe Jobs::EmitWebHookEvent do
|
||||||
end.to raise_error(Discourse::InvalidParameters)
|
end.to raise_error(Discourse::InvalidParameters)
|
||||||
end
|
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
|
it "doesn't emit when the hook is inactive" do
|
||||||
subject.execute(
|
subject.execute(
|
||||||
web_hook_id: inactive_hook.id,
|
web_hook_id: inactive_hook.id,
|
||||||
|
@ -99,7 +109,7 @@ describe Jobs::EmitWebHookEvent do
|
||||||
web_hook_id: post_hook.id,
|
web_hook_id: post_hook.id,
|
||||||
event_type: described_class::PING_EVENT,
|
event_type: described_class::PING_EVENT,
|
||||||
event_name: 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
|
event = WebHookEvent.last
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue