amelioration(NotificationMailer): sort la creation des commentaire sur la messagerie du mailer [trop de prob possible sinon: au retry on dupliquait les commenaitres, si le mail foirait, on commentait pas etc...]
This commit is contained in:
parent
23fb7e812e
commit
ce9dbed663
13 changed files with 75 additions and 55 deletions
|
@ -300,6 +300,10 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
|
||||
subject
|
||||
end
|
||||
|
||||
it 'creates a commentaire' do
|
||||
expect { subject }.to change { Commentaire.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'refusal with a justificatif' do
|
||||
|
|
|
@ -34,7 +34,7 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
end
|
||||
|
||||
describe 'send_en_instruction_notification' do
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
let(:email_template) { create(:received_mail, subject: 'Email subject', body: 'Your dossier was processed. Thanks.') }
|
||||
|
||||
before do
|
||||
|
@ -43,15 +43,6 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
|
||||
subject(:mail) { described_class.send_en_instruction_notification(dossier) }
|
||||
|
||||
it 'creates a commentaire in the messagerie' do
|
||||
expect { subject.deliver_now }.to change { Commentaire.count }.by(1)
|
||||
expect(subject.perform_deliveries).to be_truthy
|
||||
|
||||
commentaire = Commentaire.last
|
||||
expect(commentaire.body).to include(email_template.subject_for_dossier(dossier), email_template.body_for_dossier(dossier))
|
||||
expect(commentaire.dossier).to eq(dossier)
|
||||
end
|
||||
|
||||
it 'renders the template' do
|
||||
expect(mail.subject).to eq('Email subject')
|
||||
expect(mail.body).to include('Your dossier was processed')
|
||||
|
@ -92,32 +83,9 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'send_accepte_notification' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
let(:email_template) { create(:closed_mail, subject: 'Email subject', body: 'Your dossier was accepted. Thanks.') }
|
||||
|
||||
before do
|
||||
dossier.procedure.closed_mail = email_template
|
||||
end
|
||||
|
||||
subject(:mail) { described_class.send_accepte_notification(dossier) }
|
||||
|
||||
context 'when dossier user is deleted' do
|
||||
before do
|
||||
dossier.user.delete_and_keep_track_dossiers_also_delete_user(administrateur)
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it 'should not send notification' do
|
||||
expect { subject.deliver_now }.not_to change { Commentaire.count }
|
||||
expect(subject.perform_deliveries).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'subject length' do
|
||||
let(:procedure) { create(:simple_procedure, libelle: "My super long title " + ("xo " * 100)) }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :accepte, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
let(:email_template) { create(:closed_mail, subject:, body: 'Your dossier was accepted. Thanks.') }
|
||||
|
||||
before do
|
||||
|
@ -141,10 +109,10 @@ RSpec.describe NotificationMailer, type: :mailer do
|
|||
describe 'subject with apostrophe' do
|
||||
let(:procedure) { create(:simple_procedure, libelle: "Mon titre avec l'apostrophe") }
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_individual, :with_service, user: user, procedure: procedure) }
|
||||
let(:email_template) { create(:closed_mail, subject:, body: 'Your dossier was accepted. Thanks.') }
|
||||
let(:email_template) { create(:received_mail, subject:, body: 'Your dossier was accepted. Thanks.') }
|
||||
|
||||
before do
|
||||
dossier.procedure.closed_mail = email_template
|
||||
dossier.procedure.received_mail = email_template
|
||||
end
|
||||
|
||||
subject(:mail) { described_class.send_accepte_notification(dossier) }
|
||||
|
|
|
@ -265,7 +265,7 @@ describe DossierRebaseConcern do
|
|||
]
|
||||
end
|
||||
let(:types_de_champ_private) { [{ type: :text, stable_id: 11 }] }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) }
|
||||
let(:types_de_champ) { procedure.active_revision.types_de_champ }
|
||||
|
||||
let(:text_type_de_champ) { types_de_champ.find { _1.stable_id == 1 } }
|
||||
|
|
|
@ -1008,6 +1008,7 @@ describe Dossier, type: :model do
|
|||
it { expect(operation_serialized['executed_at']).to eq(last_operation.executed_at.iso8601) }
|
||||
it { expect(NotificationMailer).to have_received(:send_accepte_notification).with(dossier) }
|
||||
it { expect(dossier.attestation).to eq(attestation) }
|
||||
it { expect(dossier.commentaires.count).to eq(1) }
|
||||
end
|
||||
|
||||
describe '#accepter_automatiquement!' do
|
||||
|
@ -1061,6 +1062,7 @@ describe Dossier, type: :model do
|
|||
expect(last_operation.automatic_operation?).to be_truthy
|
||||
expect(NotificationMailer).to have_received(:send_accepte_notification).with(dossier)
|
||||
expect(subject.attestation).to eq(attestation)
|
||||
expect(dossier.commentaires.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1082,11 +1084,21 @@ describe Dossier, type: :model do
|
|||
it { expect(operation_serialized['operation']).to eq('passer_en_instruction') }
|
||||
it { expect(operation_serialized['dossier_id']).to eq(dossier.id) }
|
||||
it { expect(operation_serialized['executed_at']).to eq(last_operation.executed_at.iso8601) }
|
||||
it { expect(dossier.commentaires.count).to eq(1) }
|
||||
|
||||
it "resolve pending correction" do
|
||||
expect(dossier.pending_correction?).to be_falsey
|
||||
expect(correction.reload.resolved_at).to be_present
|
||||
end
|
||||
|
||||
it 'creates a commentaire in the messagerie with expected wording' do
|
||||
email_template = dossier.procedure.mail_template_for(Dossier.states.fetch(:en_instruction))
|
||||
commentaire = dossier.commentaires.first
|
||||
|
||||
expect(dossier.commentaires.count).to eq(1)
|
||||
expect(commentaire.body).to include(email_template.subject_for_dossier(dossier), email_template.body_for_dossier(dossier))
|
||||
expect(commentaire.dossier).to eq(dossier)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#passer_automatiquement_en_instruction!' do
|
||||
|
@ -1111,6 +1123,7 @@ describe Dossier, type: :model do
|
|||
expect(operation_serialized['operation']).to eq('passer_en_instruction')
|
||||
expect(operation_serialized['dossier_id']).to eq(dossier.id)
|
||||
expect(operation_serialized['executed_at']).to eq(last_operation.executed_at.iso8601)
|
||||
expect(dossier.commentaires.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue