This commit is contained in:
Kara Diaby 2022-01-05 10:43:20 +01:00
parent 4606650248
commit bdcb0ca0e9
3 changed files with 31 additions and 13 deletions

View file

@ -1028,13 +1028,13 @@ describe Users::DossiersController, type: :controller do
subject
end
it "deletes the dossier" do
it "hide the dossier and create a deleted dossier" do
procedure = dossier.procedure
dossier_id = dossier.id
subject
expect(Dossier.find_by(id: dossier_id)).to eq(nil)
expect(Dossier.find_by(id: dossier_id)).to be_present
expect(Dossier.find_by(id: dossier_id).hidden_by_user_at).to be_present
expect(procedure.deleted_dossiers.count).to eq(1)
expect(procedure.deleted_dossiers.first.dossier_id).to eq(dossier_id)
end
it { is_expected.to redirect_to(dossiers_path) }
@ -1065,6 +1065,21 @@ describe Users::DossiersController, type: :controller do
end
end
describe '#restore' do
before { sign_in(user) }
subject { patch :restore, params: { id: dossier.id } }
context 'when the user want to restore his dossier' do
let!(:dossier) { create(:dossier, :with_individual, state: :accepte, en_construction_at: Time.zone.yesterday.beginning_of_day.utc, hidden_by_user_at: Time.zone.yesterday.beginning_of_day.utc, user: user, autorisation_donnees: true) }
before { subject }
it 'must have hidden_by_user_at nil' do
expect(dossier.reload.hidden_by_user_at).to be_nil
end
end
end
describe '#new' do
let(:procedure) { create(:procedure, :published) }
let(:procedure_id) { procedure.id }

View file

@ -793,6 +793,7 @@ describe Dossier do
describe "#discard_and_keep_track!" do
let(:dossier) { create(:dossier, :en_construction) }
let(:user) { dossier.user }
let(:deleted_dossier) { DeletedDossier.find_by(dossier_id: dossier.id) }
let(:last_operation) { dossier.dossier_operation_logs.last }
let(:reason) { :user_request }
@ -802,7 +803,7 @@ describe Dossier do
allow(DossierMailer).to receive(:notify_deletion_to_administration).and_return(double(deliver_later: nil))
end
subject! { dossier.discard_and_keep_track!(dossier.user, reason) }
subject! { dossier.discard_and_keep_track!(user, reason) }
context 'brouillon' do
let(:dossier) { create(:dossier) }
@ -821,8 +822,9 @@ describe Dossier do
end
context 'en_construction' do
it 'hides the dossier' do
expect(dossier.hidden_at).to be_present
it 'hide the dossier but does not discard' do
expect(dossier.hidden_at).to be_nil
expect(dossier.hidden_by_user_at).to be_present
end
it 'creates a DeletedDossier record' do
@ -872,6 +874,7 @@ describe Dossier do
end
context 'with reason: manager_request' do
let(:user) { dossier.procedure.administrateurs.first }
let(:reason) { :manager_request }
it 'hides the dossier' do
@ -887,13 +890,12 @@ describe Dossier do
context 'with reason: user_removed' do
let(:reason) { :user_removed }
it 'hides the dossier' do
expect(dossier.discarded?).to be_truthy
it 'does not discard the dossier' do
expect(dossier.discarded?).to be_falsy
end
it 'records the operation in the log' do
expect(last_operation.operation).to eq("supprimer")
expect(last_operation.automatic_operation?).to be_falsey
it 'hide the dossier' do
expect(dossier.hidden_by_user_at).to be_present
end
end
end

View file

@ -12,7 +12,8 @@ describe 'users/dossiers/index.html.haml', type: :view do
allow(controller).to receive(:current_user) { user }
assign(:user_dossiers, Kaminari.paginate_array(user_dossiers).page(1))
assign(:dossiers_invites, Kaminari.paginate_array(dossiers_invites).page(1))
assign(:dossiers_supprimes, Kaminari.paginate_array(user_dossiers).page(1))
assign(:dossiers_supprimes_recemment, Kaminari.paginate_array(user_dossiers).page(1))
assign(:dossiers_supprimes_definitivement, Kaminari.paginate_array(user_dossiers).page(1))
assign(:dossiers_traites, Kaminari.paginate_array(user_dossiers).page(1))
assign(:dossier_transfers, Kaminari.paginate_array([]).page(1))
assign(:dossiers_close_to_expiration, Kaminari.paginate_array([]).page(1))
@ -69,7 +70,7 @@ describe 'users/dossiers/index.html.haml', type: :view do
it 'affiche la barre donglets' do
expect(rendered).to have_selector('nav.tabs')
expect(rendered).to have_selector('nav.tabs li', count: 4)
expect(rendered).to have_selector('nav.tabs li', count: 5)
expect(rendered).to have_selector('nav.tabs li.active', count: 1)
end
end