Merge pull request #7440 from betagouv/US/avoid-same-webhook-notification

fix(webhook.perform): enqueue WebHookJob with current state/updated_at for consistency reason
This commit is contained in:
mfo 2022-06-01 16:59:45 +02:00 committed by GitHub
commit 7cea474231
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 9 deletions

View file

@ -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)

View file

@ -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

View file

@ -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