fix(webhook.perform): ensure to enqueue job with current state/updated_at for consistency reason
This commit is contained in:
parent
1c2b5690ad
commit
d39b3b09ed
3 changed files with 11 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue