dossier: send deletion email also to the following gestionnaires

This commit is contained in:
Pierre de La Morinerie 2018-07-23 13:06:06 +00:00
parent 6daa31d410
commit 13182ad291
2 changed files with 27 additions and 3 deletions

View file

@ -276,8 +276,12 @@ class Dossier < ApplicationRecord
now = Time.now
deleted_dossier = DeletedDossier.create!(dossier_id: id, procedure: procedure, state: state, deleted_at: now)
update(hidden_at: now)
administration_emails = followers_gestionnaires.present? ? followers_gestionnaires.pluck(:email) : [procedure.administrateur.email]
administration_emails.each do |email|
DossierMailer.notify_deletion_to_administration(deleted_dossier, email).deliver_later
end
DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later
DossierMailer.notify_deletion_to_administration(deleted_dossier, procedure.administrateur.email).deliver_later
end
private

View file

@ -828,9 +828,29 @@ describe Dossier do
expect(deleted_dossier.deleted_at).to be_present
end
it 'sends notification emails' do
it 'notifies the user' do
expect(DossierMailer).to have_received(:notify_deletion_to_user).with(deleted_dossier, dossier.user.email)
expect(DossierMailer).to have_received(:notify_deletion_to_administration).with(deleted_dossier, dossier.procedure.administrateur.email)
end
context 'where gestionnaires are following the dossier' do
let(:dossier) { create(:dossier, :followed) }
let!(:non_following_gestionnaire) do
non_following_gestionnaire = create(:gestionnaire)
non_following_gestionnaire.procedures << dossier.procedure
non_following_gestionnaire
end
it 'notifies the following gestionnaires' do
expect(DossierMailer).to have_received(:notify_deletion_to_administration).once
expect(DossierMailer).to have_received(:notify_deletion_to_administration).with(deleted_dossier, dossier.followers_gestionnaires.first.email)
end
end
context 'when there are no following gestionnaires' do
it 'notifies the procedure administrateur' do
expect(DossierMailer).to have_received(:notify_deletion_to_administration).once
expect(DossierMailer).to have_received(:notify_deletion_to_administration).with(deleted_dossier, dossier.procedure.administrateur.email)
end
end
end