DEV: Reserve webhook event types to be used in plugins (#9110)

* DEV: Reserve webhook event types to be used in plugins

Based on feedback on the following PR's:

https://github.com/discourse/discourse-solved/pull/85

https://github.com/discourse/discourse-assign/pull/61

This commit reserves ID's to be used for webhook event types to ensure
that some other webhook or plugin doesn't end up using the same ID.

* Fix broken test

I don't think this test has to test ALL event types to verify that this
feature is working. Now that we added some event types that plugins are
using this test was failing for missing fabricators that exist in the
respective plugins.

* remove loop and just test first record
This commit is contained in:
Blake Erickson 2020-03-06 10:16:19 -07:00 committed by GitHub
parent ef6b7bd776
commit 43b54c631d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -11,6 +11,8 @@ class WebHookEventType < ActiveRecord::Base
QUEUED_POST = 8 QUEUED_POST = 8
REVIEWABLE = 9 REVIEWABLE = 9
NOTIFICATION = 10 NOTIFICATION = 10
SOLVED = 11
ASSIGN = 12
has_and_belongs_to_many :web_hooks has_and_belongs_to_many :web_hooks

View File

@ -49,3 +49,13 @@ WebHookEventType.seed do |b|
b.id = WebHookEventType::NOTIFICATION b.id = WebHookEventType::NOTIFICATION
b.name = "notification" b.name = "notification"
end end
WebHookEventType.seed do |b|
b.id = WebHookEventType::SOLVED
b.name = "solved"
end
WebHookEventType.seed do |b|
b.id = WebHookEventType::ASSIGN
b.name = "assign"
end

View File

@ -239,17 +239,16 @@ describe Jobs::EmitWebHookEvent do
stub_request(:post, post_hook.payload_url) stub_request(:post, post_hook.payload_url)
.to_return(body: 'OK', status: 200) .to_return(body: 'OK', status: 200)
WebHookEventType.all.pluck(:name).each do |name| topic_event_type = WebHookEventType.all.first
web_hook_id = Fabricate("#{name}_web_hook").id web_hook_id = Fabricate("#{topic_event_type.name}_web_hook").id
expect do expect do
subject.execute( subject.execute(
web_hook_id: web_hook_id, web_hook_id: web_hook_id,
event_type: name, event_type: topic_event_type.name,
payload: { test: "some payload" }.to_json payload: { test: "some payload" }.to_json
) )
end.to change(WebHookEvent, :count).by(1) end.to change(WebHookEvent, :count).by(1)
end
end end
it 'sets up proper request headers' do it 'sets up proper request headers' do