SPEC: Add test case in emit_web_hook_event_spec for commit 4c6bfb9

SPEC: Add test case in emit_web_hook_event_spec for commit 4c6bfb9

diff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rb
index 06aadf8..099234b 100644
--- a/spec/jobs/emit_web_hook_event_spec.rb
+++ b/spec/jobs/emit_web_hook_event_spec.rb
@@ -1,4 +1,5 @@
 require 'rails_helper'
+require 'excon'
 
 describe Jobs::EmitWebHookEvent do
   let(:post_hook) { Fabricate(:web_hook) }
@@ -24,6 +25,16 @@ describe Jobs::EmitWebHookEvent do
     end.to raise_error(Discourse::InvalidParameters)
   end
 
+  it "should not destroy webhook event in case of error" do
+    Excon::Connection.any_instance.stubs(:post).raises("error")
+    subject.execute(
+      web_hook_id: post_hook.id,
+      payload: { id: post.id }.to_json,
+      event_type: WebHookEventType::POST
+    )
+    expect(WebHookEvent.last.web_hook_id).to eq(post_hook.id)
+  end
+
   context 'when the web hook is failed' do
     before do
       SiteSetting.retry_web_hook_events = true

GitHub sha: 904ba266

Instead of stubbing the method which relies on the internal implementation detail, we can stub at the request level which is not coupled to the library which we use to make the request.

2 Likes

Was followed in DEV: Refactor `Jobs::EmitWebHookEvent` specs. · discourse/discourse@730ebdf · GitHub

1 Like