Merge pull request #2287 from betagouv/send-delete-notifications-to-following-gestionnaires
Envoie un email signalant la suppression d'un dossier aux Accompagnants
This commit is contained in:
commit
3e4c5b4440
2 changed files with 53 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -806,6 +806,54 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#delete_and_keep_track" do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:deleted_dossier) { DeletedDossier.find_by!(dossier_id: dossier.id) }
|
||||
|
||||
before do
|
||||
allow(DossierMailer).to receive(:notify_deletion_to_user).and_return(double(deliver_later: nil))
|
||||
allow(DossierMailer).to receive(:notify_deletion_to_administration).and_return(double(deliver_later: nil))
|
||||
end
|
||||
|
||||
subject! { dossier.delete_and_keep_track }
|
||||
|
||||
it 'hides the dossier' do
|
||||
expect(dossier.hidden_at).to be_present
|
||||
end
|
||||
|
||||
it 'creates a DeletedDossier record' do
|
||||
expect(deleted_dossier.dossier_id).to eq dossier.id
|
||||
expect(deleted_dossier.procedure).to eq dossier.procedure
|
||||
expect(deleted_dossier.state).to eq dossier.state
|
||||
expect(deleted_dossier.deleted_at).to be_present
|
||||
end
|
||||
|
||||
it 'notifies the user' do
|
||||
expect(DossierMailer).to have_received(:notify_deletion_to_user).with(deleted_dossier, dossier.user.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
|
||||
|
||||
describe 'webhook' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue