diff --git a/app/jobs/web_hook_job.rb b/app/jobs/web_hook_job.rb index 3e6df8585..d0f95b83e 100644 --- a/app/jobs/web_hook_job.rb +++ b/app/jobs/web_hook_job.rb @@ -3,12 +3,12 @@ class WebHookJob < ApplicationJob TIMEOUT = 10 - def perform(procedure, dossier) + def perform(procedure_id, dossier_id, state, updated_at) body = { - procedure_id: procedure.id, - dossier_id: dossier.id, - state: dossier.state, - updated_at: dossier.updated_at + procedure_id: procedure_id, + dossier_id: dossier_id, + state: state, + updated_at: updated_at } Typhoeus.post(procedure.web_hook_url, body: body, timeout: TIMEOUT) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 5751b3619..650b8de68 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1251,8 +1251,10 @@ class Dossier < ApplicationRecord def send_web_hook if saved_change_to_state? && !brouillon? && procedure.web_hook_url.present? WebHookJob.perform_later( - procedure, - self + procedure.id, + self.id, + self.state, + self.updated_at ) end end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index db59d6708..01e6d2368 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -962,7 +962,7 @@ describe Dossier do expect { dossier.passer_en_construction! - }.to have_enqueued_job(WebHookJob) + }.to have_enqueued_job(WebHookJob).with(dossier.procedure.id, dossier.id, 'en_construction', anything) expect { dossier.update_column(:search_terms, 'bonjour2') @@ -970,7 +970,7 @@ describe Dossier do expect { dossier.passer_en_instruction!(instructeur: instructeur) - }.to have_enqueued_job(WebHookJob) + }.to have_enqueued_job(WebHookJob).with(dossier.procedure.id, dossier.id, 'en_instruction', anything) end end