From 43b54c631d0804ddb29cb72bdae3deba326f194d Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Fri, 6 Mar 2020 10:16:19 -0700 Subject: [PATCH] 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 --- app/models/web_hook_event_type.rb | 2 ++ db/fixtures/007_web_hook_event_types.rb | 10 ++++++++++ spec/jobs/emit_web_hook_event_spec.rb | 19 +++++++++---------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/models/web_hook_event_type.rb b/app/models/web_hook_event_type.rb index 719ceaa712e..c40c7a21a90 100644 --- a/app/models/web_hook_event_type.rb +++ b/app/models/web_hook_event_type.rb @@ -11,6 +11,8 @@ class WebHookEventType < ActiveRecord::Base QUEUED_POST = 8 REVIEWABLE = 9 NOTIFICATION = 10 + SOLVED = 11 + ASSIGN = 12 has_and_belongs_to_many :web_hooks diff --git a/db/fixtures/007_web_hook_event_types.rb b/db/fixtures/007_web_hook_event_types.rb index 0645cfad8e5..5cbcd3edc2a 100644 --- a/db/fixtures/007_web_hook_event_types.rb +++ b/db/fixtures/007_web_hook_event_types.rb @@ -49,3 +49,13 @@ WebHookEventType.seed do |b| b.id = WebHookEventType::NOTIFICATION b.name = "notification" 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 diff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rb index e87d6b7c7c4..453db11abb2 100644 --- a/spec/jobs/emit_web_hook_event_spec.rb +++ b/spec/jobs/emit_web_hook_event_spec.rb @@ -239,17 +239,16 @@ describe Jobs::EmitWebHookEvent do stub_request(:post, post_hook.payload_url) .to_return(body: 'OK', status: 200) - WebHookEventType.all.pluck(:name).each do |name| - web_hook_id = Fabricate("#{name}_web_hook").id + topic_event_type = WebHookEventType.all.first + web_hook_id = Fabricate("#{topic_event_type.name}_web_hook").id - expect do - subject.execute( - web_hook_id: web_hook_id, - event_type: name, - payload: { test: "some payload" }.to_json - ) - end.to change(WebHookEvent, :count).by(1) - end + expect do + subject.execute( + web_hook_id: web_hook_id, + event_type: topic_event_type.name, + payload: { test: "some payload" }.to_json + ) + end.to change(WebHookEvent, :count).by(1) end it 'sets up proper request headers' do