From 46e75ac8efc8fc1a8739086026d041ecc59bb816 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 2 Aug 2018 16:36:50 +0200 Subject: [PATCH] Only notify on dossier supression if dossier is en_construction --- app/models/dossier.rb | 8 +++++--- spec/controllers/new_user/dossiers_controller_spec.rb | 2 +- spec/models/dossier_spec.rb | 10 +++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 12d6eb53a..ce7dbae03 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -291,9 +291,11 @@ class Dossier < ApplicationRecord 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 + if en_construction? + 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 end DossierMailer.notify_deletion_to_user(deleted_dossier, user.email).deliver_later end diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index 3d891b1f9..15f75cae1 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -498,7 +498,7 @@ describe NewUser::DossiersController, type: :controller do end context 'when dossier is owned by signed in user' do - let(:dossier) { create(:dossier, user: user, autorisation_donnees: true) } + let(:dossier) { create(:dossier, :en_construction, user: user, autorisation_donnees: true) } it do expect(DossierMailer).to receive(:notify_deletion_to_administration).with(kind_of(DeletedDossier), dossier.procedure.administrateur.email).and_return(double(deliver_later: nil)) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index dbc79fffe..e873d2448 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -859,7 +859,7 @@ describe Dossier do end context 'where gestionnaires are following the dossier' do - let(:dossier) { create(:dossier, :followed) } + let(:dossier) { create(:dossier, :en_construction, :followed) } let!(:non_following_gestionnaire) do non_following_gestionnaire = create(:gestionnaire) non_following_gestionnaire.procedures << dossier.procedure @@ -873,11 +873,19 @@ describe Dossier do end context 'when there are no following gestionnaires' do + let(:dossier) { create(:dossier, :en_construction) } 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 + + context 'when dossier is brouillon' do + let(:dossier) { create(:dossier) } + it 'do not notifies the procedure administrateur' do + expect(DossierMailer).not_to have_received(:notify_deletion_to_administration) + end + end end describe 'webhook' do