test(dossier): update spec to use visible_by_administration

This commit is contained in:
Paul Chavard 2022-03-09 10:29:16 +01:00
parent 54b559364a
commit 51d7fd6190
16 changed files with 106 additions and 142 deletions

View file

@ -139,11 +139,6 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
let!(:gi_1_2) { procedure.groupe_instructeurs.create(label: 'groupe instructeur 2') }
let!(:gi_1_3) { procedure.groupe_instructeurs.create(label: 'groupe instructeur 3') }
let!(:dossier12) { create(:dossier, :en_construction, :with_individual, procedure: procedure, groupe_instructeur: gi_1_1) }
let!(:dossier_discarded) do
dossier = create(:dossier, :en_construction, :with_individual, procedure: procedure, groupe_instructeur: gi_1_1)
dossier.discard!
dossier
end
let!(:instructeur) { create(:instructeur) }
let!(:bulk_message) { BulkMessage.create(dossier_count: 2, dossier_state: "brouillon", body: "hello", sent_at: Time.zone.now, groupe_instructeurs: [gi_1_1, gi_1_3], instructeur: instructeur) }
@ -160,8 +155,6 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
end
it { expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure)) }
it { expect(gi_1_1.dossiers.with_discarded.count).to be(0) }
it { expect(gi_1_2.dossiers.with_discarded.count).to be(2) }
it { expect(gi_1_2.dossiers.last.id).to be(dossier12.id) }
it { expect(dossier12.groupe_instructeur.id).to be(gi_1_2.id) }
it { expect(bulk_message.groupe_instructeurs).to contain_exactly(gi_1_2, gi_1_3) }

View file

@ -387,12 +387,8 @@ describe Administrateurs::ProceduresController, type: :controller do
before { subject }
it 'discard the procedure' do
expect(procedure.reload.discarded?).to be_truthy
end
it 'deletes associated dossiers' do
expect(procedure.dossiers.with_discarded.count).to eq(0)
expect(procedure.dossiers.count).to eq(0)
end
it 'redirects to the procedure drafts page' do
@ -414,7 +410,7 @@ describe Administrateurs::ProceduresController, type: :controller do
it do
expect(procedure.reload.close?).to be_truthy
expect(procedure.discarded?).to be_truthy
expect(dossier.reload.kept?).to be_truthy
expect(dossier.reload.visible_by_administration?).to be_falsy
end
end
@ -441,7 +437,7 @@ describe Administrateurs::ProceduresController, type: :controller do
it do
expect(procedure.reload.discarded?).to be_truthy
expect(dossier.reload.kept?).to be_truthy
expect(dossier.reload.visible_by_administration?).to be_falsy
end
end

View file

@ -778,8 +778,8 @@ describe Instructeurs::DossiersController, type: :controller do
expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(0)
end
it 'discard the dossier' do
expect(dossier.reload.hidden_at).not_to eq(nil)
it 'is not visible by administration' do
expect(dossier.reload.visible_by_administration?).to be_falsy
end
end
@ -789,9 +789,9 @@ describe Instructeurs::DossiersController, type: :controller do
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')
it 'does not deletes previous logs and adds a suppression log' do
expect(DossierOperationLog.where(dossier_id: dossier.id).count).to eq(3)
expect(DossierOperationLog.where(dossier_id: dossier.id).last.operation).to eq('supprimer')
end
it 'add a record into deleted_dossiers table' do
@ -845,8 +845,8 @@ describe Instructeurs::DossiersController, type: :controller do
describe '#restore' do
let(:instructeur) { create(:instructeur) }
let!(:gi_p1_1) { GroupeInstructeur.create(label: '1', procedure: procedure) }
let!(:procedure) { create(:procedure, :published, instructeurs: [instructeur]) }
let!(:dossier) { create(:dossier, state: 'accepte', procedure: procedure, groupe_instructeur: procedure.groupe_instructeurs.first, hidden_by_administration_at: 1.hour.ago) }
let!(:procedure) { create(:procedure, :published, :for_individual, instructeurs: [instructeur]) }
let!(:dossier) { create(:dossier, :accepte, :with_individual, procedure: procedure, groupe_instructeur: procedure.groupe_instructeurs.first, hidden_by_administration_at: 1.hour.ago) }
before do
sign_in(instructeur.user)

View file

@ -76,7 +76,7 @@ describe Instructeurs::ProceduresController, type: :controller do
end
context "with dossiers" do
let(:procedure) { create(:procedure, :published) }
let(:procedure) { create(:procedure, :published, :expirable) }
let(:dossier) { create(:dossier, state: state, procedure: procedure) }
before do
@ -93,37 +93,54 @@ describe Instructeurs::ProceduresController, type: :controller do
it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(nil) }
it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure.id]).to eq(nil) }
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(nil) }
it { expect(assigns(:dossiers_expirant_count_per_procedure)[procedure.id]).to eq(nil) }
it { expect(assigns(:all_dossiers_counts)['à suivre']).to eq(0) }
it { expect(assigns(:all_dossiers_counts)['suivis']).to eq(0) }
it { expect(assigns(:all_dossiers_counts)['traités']).to eq(0) }
it { expect(assigns(:all_dossiers_counts)['dossiers']).to eq(0) }
it { expect(assigns(:all_dossiers_counts)['archivés']).to eq(0) }
it { expect(assigns(:all_dossiers_counts)['expirant']).to eq(0) }
end
context "with not draft state on multiple procedures" do
let(:procedure2) { create(:procedure, :published) }
let(:procedure2) { create(:procedure, :published, :expirable) }
let(:state) { Dossier.states.fetch(:en_construction) }
before do
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction))
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction), hidden_by_user_at: 1.hour.ago)
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction))
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:sans_suite), archived: true)
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:sans_suite), archived: true,
hidden_by_administration_at: 1.day.ago)
instructeur.groupe_instructeurs << procedure2.defaut_groupe_instructeur
create(:dossier, :followed, procedure: procedure2, state: Dossier.states.fetch(:en_construction))
create(:dossier, procedure: procedure2, state: Dossier.states.fetch(:accepte))
instructeur.followed_dossiers << create(:dossier, procedure: procedure2, state: Dossier.states.fetch(:en_instruction))
create(:dossier, procedure: procedure,
state: Dossier.states.fetch(:sans_suite),
processed_at: 8.months.ago) # counted as expirable
create(:dossier, procedure: procedure,
state: Dossier.states.fetch(:sans_suite),
processed_at: 8.months.ago,
hidden_by_administration_at: 1.day.ago) # not counted as expirable since its removed by instructeur
create(:dossier, procedure: procedure,
state: Dossier.states.fetch(:sans_suite),
processed_at: 8.months.ago,
hidden_by_user_at: 1.day.ago) # counted as expirable because even if user remove it, instructeur see it
subject
end
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(3) }
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(5) }
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure.id]).to eq(3) }
it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure.id]).to eq(nil) }
it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(1) }
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(nil) }
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(2) }
it { expect(assigns(:dossiers_expirant_count_per_procedure)[procedure.id]).to eq(2) }
it { expect(assigns(:dossiers_count_per_procedure)[procedure2.id]).to eq(3) }
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure2.id]).to eq(nil) }
@ -133,9 +150,10 @@ describe Instructeurs::ProceduresController, type: :controller do
it { expect(assigns(:all_dossiers_counts)['à suivre']).to eq(3 + 0) }
it { expect(assigns(:all_dossiers_counts)['suivis']).to eq(0 + 1) }
it { expect(assigns(:all_dossiers_counts)['traités']).to eq(0 + 1) }
it { expect(assigns(:all_dossiers_counts)['dossiers']).to eq(3 + 3) }
it { expect(assigns(:all_dossiers_counts)['traités']).to eq(2 + 1) }
it { expect(assigns(:all_dossiers_counts)['dossiers']).to eq(5 + 3) }
it { expect(assigns(:all_dossiers_counts)['archivés']).to eq(1 + 0) }
it { expect(assigns(:all_dossiers_counts)['expirant']).to eq(2 + 0) }
end
end
@ -205,7 +223,7 @@ describe Instructeurs::ProceduresController, type: :controller do
describe "#show" do
let(:instructeur) { create(:instructeur) }
let!(:procedure) { create(:procedure, instructeurs: [instructeur]) }
let!(:procedure) { create(:procedure, :expirable, instructeurs: [instructeur]) }
let!(:gi_2) { procedure.groupe_instructeurs.create(label: '2') }
let!(:gi_3) { procedure.groupe_instructeurs.create(label: '3') }
let(:statut) { nil }
@ -323,6 +341,7 @@ describe Instructeurs::ProceduresController, type: :controller do
context 'with an archived dossier' do
let!(:archived_dossier) { create(:dossier, :en_instruction, procedure: procedure, archived: true) }
let!(:archived_dossier_deleted) { create(:dossier, :en_instruction, procedure: procedure, archived: true, hidden_by_administration_at: 2.days.ago) }
before { subject }
@ -342,6 +361,16 @@ describe Instructeurs::ProceduresController, type: :controller do
end
end
context 'with an expirants dossier' do
let!(:expiring_dossier_termine_deleted) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago, hidden_by_administration_at: 2.days.ago) }
let!(:expiring_dossier_termine) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago) }
let!(:expiring_dossier_en_construction) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: 175.days.ago) }
before { subject }
it { expect(assigns(:expirant_dossiers)).to match_array([expiring_dossier_termine, expiring_dossier_en_construction]) }
end
describe 'statut' do
let!(:a_suivre__dossier) { Timecop.freeze(1.day.ago) { create(:dossier, :en_instruction, procedure: procedure) } }
let!(:new_followed_dossier) { Timecop.freeze(2.days.ago) { create(:dossier, :en_instruction, procedure: procedure) } }

View file

@ -1069,15 +1069,6 @@ 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_administration_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 '#restore' do

View file

@ -6,5 +6,17 @@ FactoryBot.define do
deleted_at { Time.zone.now }
association :procedure, :published
transient do
dossier { nil }
end
after(:build) do |deleted_dossier, evaluator|
if evaluator.dossier
deleted_dossier.dossier_id = evaluator.dossier.id
deleted_dossier.state = evaluator.dossier.state
deleted_dossier.procedure = evaluator.dossier.procedure
end
end
end
end

View file

@ -81,7 +81,9 @@ FactoryBot.define do
trait :with_logo do
logo { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
end
trait :expirable do
procedure_expires_when_termine_enabled { true }
end
trait :with_path do
path { generate(:published_path) }
end

View file

@ -7,7 +7,7 @@ RSpec.describe Cron::DiscardedDossiersDeletionJob, type: :job do
# hack to add passer_en_instruction and supprimer to dossier.dossier_operation_logs
dossier.send(:log_dossier_operation, instructeur, :passer_en_instruction, dossier)
dossier.send(:log_dossier_operation, instructeur, :supprimer, dossier)
dossier.update_column(:hidden_at, hidden_at)
dossier.update_columns(hidden_by_user_at: hidden_at, hidden_by_administration_at: hidden_at)
dossier.update_column(:hidden_by_reason, "user_request")
Cron::DiscardedDossiersDeletionJob.perform_now

View file

@ -2,7 +2,7 @@ RSpec.describe AvisMailer, type: :mailer do
describe '.avis_invitation' do
let(:claimant) { create(:instructeur) }
let(:expert) { create(:expert) }
let(:dossier) { create(:dossier) }
let(:dossier) { create(:dossier, :en_construction) }
let(:experts_procedure) { create(:experts_procedure, expert: expert, procedure: dossier.procedure) }
let(:avis) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, introduction: 'intro') }
@ -18,7 +18,7 @@ RSpec.describe AvisMailer, type: :mailer do
end
context 'when the dossier has been deleted before the avis was sent' do
before { dossier.update(hidden_at: Time.zone.now) }
before { dossier.update(hidden_by_user_at: 1.hour.ago) }
it 'doesnt send the email' do
expect(subject.body).to be_blank

View file

@ -117,9 +117,10 @@ RSpec.describe DossierMailer, type: :mailer do
end
describe '.notify_automatic_deletion_to_user' do
let(:deleted_dossier) { create(:deleted_dossier, dossier: dossier, reason: :expired) }
describe 'en_construction' do
let(:dossier) { create(:dossier, :en_construction) }
let(:deleted_dossier) { DeletedDossier.create_from_dossier(dossier, :expired) }
subject { described_class.notify_automatic_deletion_to_user([deleted_dossier], dossier.user.email) }
@ -132,7 +133,6 @@ RSpec.describe DossierMailer, type: :mailer do
describe 'termine' do
let(:dossier) { create(:dossier, :accepte) }
let(:deleted_dossier) { DeletedDossier.create_from_dossier(dossier, :expired) }
subject { described_class.notify_automatic_deletion_to_user([deleted_dossier], dossier.user.email) }
@ -145,8 +145,8 @@ RSpec.describe DossierMailer, type: :mailer do
end
describe '.notify_automatic_deletion_to_administration' do
let(:dossier) { create(:dossier) }
let(:deleted_dossier) { DeletedDossier.create_from_dossier(dossier, :expired) }
let(:dossier) { create(:dossier, :en_construction) }
let(:deleted_dossier) { create(:deleted_dossier, dossier: dossier, reason: :expired) }
subject { described_class.notify_automatic_deletion_to_administration([deleted_dossier], dossier.user.email) }

View file

@ -6,7 +6,6 @@ describe Dossier do
describe 'scopes' do
describe '.default_scope' do
let!(:dossier) { create(:dossier) }
let!(:discarded_dossier) { create(:dossier, :discarded) }
subject { Dossier.all }
@ -791,7 +790,7 @@ describe Dossier do
end
end
describe "#discard_and_keep_track!" do
describe "#hide_and_keep_track!" do
let(:dossier) { create(:dossier, :en_construction) }
let(:user) { dossier.user }
let(:last_operation) { dossier.dossier_operation_logs.last }
@ -801,17 +800,17 @@ describe Dossier do
allow(DossierMailer).to receive(:notify_deletion_to_administration).and_return(double(deliver_later: nil))
end
subject! { dossier.discard_and_keep_track!(user, reason) }
subject! { dossier.hide_and_keep_track!(user, reason) }
context 'brouillon' do
let(:dossier) { create(:dossier) }
it 'hides the dossier' do
expect(dossier.discarded?).to be_truthy
it 'hide the dossier' do
expect(dossier.reload.hidden_by_user_at).to be_present
end
it 'do not records the operation in the log' do
expect(last_operation).to be_nil
it 'does not records operation in the log' do
expect(dossier.reload.dossier_operation_logs.last).to eq(nil)
end
end
@ -842,30 +841,16 @@ describe Dossier do
end
end
context 'with reason: manager_request' do
let(:user) { dossier.procedure.administrateurs.first }
let(:reason) { :manager_request }
it 'hides the dossier' do
expect(dossier.discarded?).to be_truthy
end
it 'records the operation in the log' do
expect(last_operation.operation).to eq("supprimer")
expect(last_operation.automatic_operation?).to be_falsey
end
end
context 'with reason: user_removed' do
let(:reason) { :user_removed }
it 'does not discard the dossier' do
expect(dossier.discarded?).to be_falsy
end
it 'hide the dossier' do
expect(dossier.hidden_by_user_at).to be_present
end
it 'write the good reason to hidden_by_reason' do
expect(dossier.hidden_by_reason).to eq("user_removed")
end
end
end
@ -876,10 +861,6 @@ describe Dossier do
it 'affect the right deletion reason to the dossier' do
expect(dossier.hidden_by_reason).to eq("user_request")
end
it 'discard the dossier' do
expect(dossier.discarded?).to be_truthy
end
end
end
@ -1308,7 +1289,7 @@ describe Dossier do
end
end
describe 'discarded_brouillon_expired and discarded_en_construction_expired' do
describe 'brouillon_expired and en_construction_expired' do
let(:administrateur) { create(:administrateur) }
let(:user) { administrateur.user }
let(:reason) { DeletedDossier.reasons.fetch(:user_request) }
@ -1316,24 +1297,25 @@ describe Dossier do
before do
create(:dossier, user: user)
create(:dossier, :en_construction, user: user)
create(:dossier, user: user).discard_and_keep_track!(user, reason)
create(:dossier, :en_construction, user: user).discard_and_keep_track!(user, reason)
create(:dossier, user: user).hide_and_keep_track!(user, reason)
create(:dossier, :en_construction, user: user).hide_and_keep_track!(user, reason)
Timecop.travel(2.months.ago) do
create(:dossier, user: user).discard_and_keep_track!(user, reason)
create(:dossier, :en_construction, user: user).discard_and_keep_track!(user, reason)
create(:dossier, user: user).hide_and_keep_track!(user, reason)
create(:dossier, :en_construction, user: user).hide_and_keep_track!(user, reason)
create(:dossier, user: user).procedure.discard_and_keep_track!(administrateur)
create(:dossier, :en_construction, user: user).procedure.discard_and_keep_track!(administrateur)
end
Timecop.travel(1.week.ago) do
create(:dossier, user: user).discard_and_keep_track!(user, reason)
create(:dossier, :en_construction, user: user).discard_and_keep_track!(user, reason)
create(:dossier, user: user).hide_and_keep_track!(user, reason)
create(:dossier, :en_construction, user: user).hide_and_keep_track!(user, reason)
end
end
it { expect(Dossier.discarded_brouillon_expired.count).to eq(2) }
it { expect(Dossier.discarded_en_construction_expired.count).to eq(0) }
it { expect(Dossier.en_brouillon_expired_to_delete.count).to eq(2) }
it { expect(Dossier.en_construction_expired_to_delete.count).to eq(2) }
end
describe "discarded procedure dossier should be able to access it's procedure" do
@ -1529,42 +1511,6 @@ describe Dossier do
expect(dossier.destroy).to be_truthy
expect(transfer.reload).not_to be_nil
end
context 'discarded' do
context 'en_construction' do
let(:dossier) { create(:dossier, :en_construction) }
before do
create(:avis, dossier: dossier)
Timecop.travel(2.weeks.ago) do
dossier.discard!
end
dossier.reload
end
it "can destroy dossier with avis" do
Avis.discarded_en_construction_expired.destroy_all
expect(dossier.destroy).to be_truthy
end
end
context 'termine' do
let(:dossier) { create(:dossier, :accepte) }
before do
create(:avis, dossier: dossier)
Timecop.travel(2.weeks.ago) do
dossier.discard!
end
dossier.reload
end
it "can destroy dossier with avis" do
Avis.discarded_termine_expired.destroy_all
expect(dossier.destroy).to be_truthy
end
end
end
end
describe "#spreadsheet_columns" do

View file

@ -40,8 +40,8 @@ RSpec.describe DossierTransfer, type: :model do
it { expect(DossierTransfer.with_dossiers.count).to eq(1) }
context "when dossier discarded" do
before { dossier.discard! }
context "when dossier deleted" do
before { dossier.update(hidden_by_user_at: 1.hour.ago) }
it { expect(DossierTransfer.with_dossiers.count).to eq(0) }
end
@ -51,10 +51,10 @@ RSpec.describe DossierTransfer, type: :model do
describe '#destroy_and_nullify' do
let(:transfer) { create(:dossier_transfer) }
let(:dossier) { create(:dossier, user: user, transfer: transfer) }
let(:discarded_dossier) { create(:dossier, user: user, transfer: dossier.transfer) }
let(:deleted_dossier) { create(:dossier, user: user, transfer: dossier.transfer) }
before do
discarded_dossier.discard!
deleted_dossier.update(hidden_by_user_at: 1.hour.ago)
end
it 'nullify transfer relationship on dossier' do
@ -67,10 +67,10 @@ RSpec.describe DossierTransfer, type: :model do
describe '#destroy_stale' do
let(:transfer) { create(:dossier_transfer, created_at: 1.month.ago) }
let(:dossier) { create(:dossier, user: user, transfer: transfer) }
let(:discarded_dossier) { create(:dossier, user: user, transfer: dossier.transfer) }
let(:deleted_dossier) { create(:dossier, user: user, transfer: dossier.transfer) }
before do
discarded_dossier.discard!
deleted_dossier.update(hidden_by_user_at: 1.hour.ago)
end
it 'nullify the transfer on discarded dossier' do

View file

@ -721,6 +721,7 @@ describe Instructeur, type: :model do
end
context 'with an expirants dossier' do
let!(:expiring_dossier_termine_deleted) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago, hidden_by_administration_at: 2.days.ago) }
let!(:expiring_dossier_termine) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago) }
let!(:expiring_dossier_en_construction) { create(:dossier, :en_construction, en_construction_at: 175.days.ago, procedure: procedure) }
before { subject }

View file

@ -56,18 +56,18 @@ describe Invite do
end
describe "#default_scope" do
let(:dossier) { create(:dossier, hidden_at: hidden_at) }
let!(:dossier) { create(:dossier, hidden_by_user_at: hidden_by_user_at) }
let!(:invite) { create(:invite, email: "email@totor.com", dossier: dossier) }
context "when dossier is not discarded" do
let(:hidden_at) { nil }
let(:hidden_by_user_at) { nil }
it { expect(Invite.count).to eq(1) }
it { expect(Invite.all).to include(invite) }
end
context "when dossier is discarded" do
let(:hidden_at) { 1.day.ago }
let(:hidden_by_user_at) { 1.hour.ago }
it { expect(Invite.count).to eq(0) }
end

View file

@ -310,21 +310,21 @@ describe User, type: :model do
it "keep track of dossiers and delete user" do
user.delete_and_keep_track_dossiers(super_admin)
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_nil
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_nil
expect(User.find_by(id: user.id)).to be_nil
end
end
context 'with a discarded dossier' do
let(:dossier_to_discard) { create(:dossier, :en_construction, user: user) }
context 'with a deleted dossier' do
let(:dossier_to_delete) { create(:dossier, :en_construction, user: user) }
let!(:dossier_from_another_user) { create(:dossier, :en_construction, user: create(:user)) }
it "keep track of dossiers and delete user" do
dossier_to_discard.discard_and_keep_track!(super_admin, :user_request)
dossier_to_delete.hide_and_keep_track!(user, :user_request)
user.delete_and_keep_track_dossiers(super_admin)
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_nil
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_nil
expect(Dossier.find_by(id: dossier_from_another_user.id)).to be_present
expect(User.find_by(id: user.id)).to be_nil
@ -426,14 +426,14 @@ describe User, type: :model do
context 'and the old account has some stuff' do
let!(:dossier) { create(:dossier, user: old_user) }
let!(:hidden_dossier) { create(:dossier, user: old_user, hidden_at: Time.zone.now) }
let!(:hidden_dossier) { create(:dossier, user: old_user, hidden_by_user_at: 1.hour.ago) }
let!(:invite) { create(:invite, user: old_user) }
let!(:merge_log) { MergeLog.create(user: old_user, from_user_id: 1, from_user_email: 'a') }
it 'transfers the dossier' do
subject
expect(targeted_user.dossiers.with_discarded).to contain_exactly(dossier, hidden_dossier)
expect(targeted_user.dossiers).to contain_exactly(dossier, hidden_dossier)
expect(targeted_user.invites).to match([invite])
expect(targeted_user.merge_logs.first).to eq(merge_log)

View file

@ -1,16 +1,10 @@
describe 'instructeurs/procedures/_download_dossiers.html.haml', type: :view do
let(:current_instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure) }
let(:dossier_count) { 0 }
subject { render 'instructeurs/procedures/download_dossiers.html.haml', procedure: procedure, dossier_count: dossier_count, exports: {} }
context "when procedure has 0 dossier" do
it { is_expected.not_to include("Télécharger tous les dossiers") }
end
subject { render 'instructeurs/procedures/download_dossiers.html.haml', procedure: procedure, exports: {} }
context "when procedure has at least 1 dossier" do
let(:dossier_count) { 1 }
it { is_expected.to include("Télécharger tous les dossiers") }
context "With zip archive enabled" do