This commit is contained in:
Kara Diaby 2021-12-08 12:27:12 +01:00
parent 37e991ccb8
commit 598cb09c6d
5 changed files with 75 additions and 10 deletions

View file

@ -762,9 +762,10 @@ describe Instructeurs::DossiersController, type: :controller do
end
end
context 'when the instructeur want to delete a dossier with a decision' do
context 'when the instructeur want to delete a dossier with a decision and already hidden by user' do
before do
dossier.accepter!(instructeur: instructeur, motivation: "le dossier est correct")
dossier.update!(hidden_by_user_at: Time.zone.now.beginning_of_day.utc)
allow(DossierMailer).to receive(:notify_instructeur_deletion_to_user).and_return(double(deliver_later: nil))
subject
end
@ -790,6 +791,31 @@ describe Instructeurs::DossiersController, type: :controller do
end
end
context 'when the instructeur want to delete a dossier with a decision and not hidden by user' do
before do
dossier.accepter!(instructeur: instructeur, motivation: "le dossier est correct")
allow(DossierMailer).to receive(:notify_instructeur_deletion_to_user).and_return(double(deliver_later: nil))
subject
end
it 'does not deletes previous logs and does not add a suppression log' do
expect(DossierOperationLog.where(dossier_id: dossier.id).count).to eq(2)
expect(DossierOperationLog.where(dossier_id: dossier.id).last.operation).not_to eq('supprimer')
end
it 'does not send an email to the user' do
expect(DossierMailer).not_to have_received(:notify_instructeur_deletion_to_user).with(DeletedDossier.where(dossier_id: dossier.id).first, dossier.user.email)
end
it 'add a record into deleted_dossiers table' do
expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(0)
end
it 'does not discard the dossier' do
expect(dossier.reload.hidden_at).to eq(nil)
end
end
context 'when the instructeur want to delete a dossier without a decision' do
before do
subject

View file

@ -1000,10 +1000,10 @@ describe Users::DossiersController, type: :controller do
end
end
describe '#ask_deletion' do
describe '#delete_dossier' do
before { sign_in(user) }
subject { post :ask_deletion, params: { id: dossier.id } }
subject { patch :delete_dossier, params: { id: dossier.id } }
shared_examples_for "the dossier can not be deleted" do
it "doesnt notify the deletion" do
@ -1043,7 +1043,7 @@ describe Users::DossiersController, type: :controller do
let(:dossier) { create(:dossier, :en_instruction, user: user, autorisation_donnees: true) }
it_behaves_like "the dossier can not be deleted"
it { is_expected.to redirect_to(dossier_path(dossier)) }
it { is_expected.to redirect_to(dossiers_path) }
end
end
@ -1054,6 +1054,15 @@ describe Users::DossiersController, type: :controller do
it_behaves_like "the dossier can not be deleted"
it { is_expected.to redirect_to(root_path) }
end
context 'when the dossier is already deleted by instructeur' do
let!(:dossier) { create(:dossier, :with_individual, state: :accepte, en_construction_at: Time.zone.yesterday.beginning_of_day.utc, user: user, autorisation_donnees: true, hidden_by_instructeur_at: Time.zone.now.beginning_of_day.utc) }
before { subject }
it 'discard the dossier' do
expect(dossier.reload.hidden_at).to be_present
end
end
end
describe '#new' do

View file

@ -62,9 +62,9 @@ describe 'user access to the list of their dossiers' do
describe 'deletion' do
it 'should have links to delete dossiers' do
expect(page).to have_link(nil, href: ask_deletion_dossier_path(dossier_brouillon))
expect(page).to have_link(nil, href: ask_deletion_dossier_path(dossier_en_construction))
expect(page).not_to have_link(nil, href: ask_deletion_dossier_path(dossier_en_instruction))
expect(page).to have_link(nil, href: delete_dossier_dossier_path(dossier_brouillon))
expect(page).to have_link(nil, href: delete_dossier_dossier_path(dossier_en_construction))
expect(page).not_to have_link(nil, href: delete_dossier_dossier_path(dossier_en_instruction))
end
context 'when user clicks on delete button', js: true do

View file

@ -0,0 +1,30 @@
describe 'experts/avis/index.html.haml', type: :view do
let!(:expert) { create(:expert) }
let!(:claimant) { create(:instructeur) }
let!(:procedure) { create(:procedure) }
let!(:avis) { create(:avis, claimant: claimant, experts_procedure: experts_procedure) }
let!(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: procedure) }
before do
allow(view).to receive(:current_expert).and_return(avis.expert)
assign(:dossier, avis.dossier)
allow(view).to receive(:current_expert).and_return(avis.expert)
end
subject { render }
context 'when the dossier is deleted by instructeur' do
before do
avis.dossier.update!(state: "accepte", hidden_by_instructeur_at: Time.zone.now.beginning_of_day.utc)
assign(:avis_by_procedure, avis.expert.avis.includes(dossier: [groupe_instructeur: :procedure]).where(dossiers: { hidden_by_instructeur_at: nil }).to_a.group_by(&:procedure))
end
it { is_expected.not_to have_text("avis à donner") }
end
context 'when the dossier is not deleted by instructeur' do
before do
assign(:avis_by_procedure, avis.expert.avis.includes(dossier: [groupe_instructeur: :procedure]).where(dossiers: { hidden_by_instructeur_at: nil }).to_a.group_by(&:procedure))
end
it { is_expected.to have_text("avis à donner") }
end
end

View file

@ -6,12 +6,12 @@ describe 'users/dossiers/dossier_actions.html.haml', type: :view do
subject { render 'users/dossiers/dossier_actions.html.haml', dossier: dossier, current_user: user }
it { is_expected.to have_link('Commencer un autre dossier', href: commencer_url(path: procedure.path)) }
it { is_expected.to have_link('Supprimer le dossier', href: ask_deletion_dossier_path(dossier)) }
it { is_expected.to have_link('Supprimer le dossier', href: delete_dossier_dossier_path(dossier)) }
it { is_expected.to have_link('Transferer le dossier', href: transferer_dossier_path(dossier)) }
context 'when the dossier cannot be deleted' do
context 'when the dossier is termine' do
let(:dossier) { create(:dossier, :accepte, procedure: procedure) }
it { is_expected.not_to have_link('Supprimer le dossier') }
it { is_expected.to have_link('Supprimer le dossier') }
end
context 'when the procedure is closed' do