diff --git a/spec/jobs/emit_web_hook_event_spec.rb b/spec/jobs/emit_web_hook_event_spec.rb index 10ae498c9ad..f2200df9121 100644 --- a/spec/jobs/emit_web_hook_event_spec.rb +++ b/spec/jobs/emit_web_hook_event_spec.rb @@ -263,5 +263,26 @@ describe Jobs::EmitWebHookEvent do expect(MultiJson.load(event.response_headers)['Test']).to eq('string') expect(event.response_body).to eq('OK') end + + it 'sets up proper request headers when an error raised' do + Excon::Connection.any_instance.expects(:post).raises("error") + + subject.execute( + web_hook_id: post_hook.id, + event_type: described_class::PING_EVENT, + event_name: described_class::PING_EVENT, + payload: { test: "this payload shouldn't appear" }.to_json + ) + + event = WebHookEvent.last + headers = MultiJson.load(event.headers) + expect(headers['Content-Length']).to eq(13) + expect(headers['Host']).to eq("meta.discourse.org") + expect(headers['X-Discourse-Event-Id']).to eq(event.id) + expect(headers['X-Discourse-Event-Type']).to eq(described_class::PING_EVENT) + expect(headers['X-Discourse-Event']).to eq(described_class::PING_EVENT) + expect(headers['X-Discourse-Event-Signature']).to eq('sha256=162f107f6b5022353274eb1a7197885cfd35744d8d08e5bcea025d309386b7d6') + expect(event.payload).to eq(MultiJson.dump(ping: 'OK')) + end end end