amelioration(dolist_api): echoue avec un fail pour remonter dans notre gestion des retry
This commit is contained in:
parent
2de9026c13
commit
6a25120f80
4 changed files with 20 additions and 4 deletions
|
@ -17,8 +17,9 @@ class EmailEvent < ApplicationRecord
|
|||
dispatched: 'dispatched',
|
||||
dispatch_error: 'dispatch_error'
|
||||
}
|
||||
|
||||
scope :dolist, -> { where(method: 'dolist') }
|
||||
scope :dolist, -> { dolist_smtp.or(dolist_api) }
|
||||
scope :dolist_smtp, -> { where(method: 'dolist_smtp') }
|
||||
scope :dolist_api, -> { where(method: 'dolist_api') }
|
||||
scope :sendinblue, -> { where(method: 'sendinblue') }
|
||||
|
||||
class << self
|
||||
|
|
|
@ -20,7 +20,7 @@ ActiveSupport.on_load(:action_mailer) do
|
|||
if response&.dig("Result")
|
||||
mail.message_id = response.dig("Result")
|
||||
else
|
||||
Rails.logger.info "Email sent. #{mail}"
|
||||
fail "DoList delivery error. Body: #{response}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ FactoryBot.define do
|
|||
status { "dispatched" }
|
||||
|
||||
trait :dolist do
|
||||
add_attribute(:method) { "dolist" }
|
||||
add_attribute(:method) { "dolist_smtp" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,6 +26,21 @@ RSpec.describe ApplicationMailer, type: :mailer do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'dealing with Dolist API error' do
|
||||
let(:dossier) { create(:dossier, procedure: create(:simple_procedure)) }
|
||||
before do
|
||||
ActionMailer::Base.delivery_method = :dolist_api
|
||||
api_error_response = { "ResponseStatus": { "ErrorCode": "Forbidden", "Message": "Blocked non authorized request", "Errors": [] } }
|
||||
allow_any_instance_of(Dolist::API).to receive(:send_email).and_return(api_error_response)
|
||||
end
|
||||
subject { DossierMailer.with(dossier:).notify_new_draft.deliver_now }
|
||||
|
||||
it 'raise classic error to retry' do
|
||||
expect { subject }.to raise_error(MailDeliveryError)
|
||||
expect(EmailEvent.dolist_api.dispatch_error.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'dealing with Dolist API success' do
|
||||
let(:dossier) { create(:dossier, procedure: create(:simple_procedure)) }
|
||||
let(:message_id) { "29d9b692-0374-4084-8434-d9cddbced205" }
|
||||
|
|
Loading…
Reference in a new issue