2023-10-09 09:21:43 +02:00
|
|
|
describe WebHookJob, type: :job do
|
|
|
|
describe 'perform' do
|
|
|
|
let(:procedure) { create(:procedure, web_hook_url:) }
|
|
|
|
let(:dossier) { create(:dossier, procedure:) }
|
|
|
|
let(:web_hook_url) { "https://domaine.fr/callback_url" }
|
|
|
|
let(:job) { WebHookJob.new(procedure.id, dossier.id, dossier.state, dossier.updated_at) }
|
|
|
|
|
|
|
|
context 'with success on webhook' do
|
|
|
|
it 'calls webhook' do
|
|
|
|
stub_request(:post, web_hook_url).to_return(status: 200, body: "success")
|
|
|
|
expect { job.perform_now }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with error on webhook' do
|
|
|
|
it 'raises' do
|
2023-10-10 09:46:28 +02:00
|
|
|
allow(Sentry).to receive(:capture_message)
|
2023-10-09 09:21:43 +02:00
|
|
|
stub_request(:post, web_hook_url).to_return(status: 500, body: "error")
|
2023-10-10 09:46:28 +02:00
|
|
|
|
|
|
|
job.perform_now
|
|
|
|
expect(Sentry).to have_received(:capture_message)
|
2023-10-09 09:21:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|