tests
This commit is contained in:
parent
a6b2873bfc
commit
24ff41d2c0
5 changed files with 33 additions and 39 deletions
|
@ -774,11 +774,8 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
expect(DossierOperationLog.where(dossier_id: dossier.id).last.operation).to eq('supprimer')
|
||||
end
|
||||
|
||||
it 'add a record into deleted_dossiers table' do
|
||||
expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(1)
|
||||
expect(DeletedDossier.where(dossier_id: dossier.id).first.revision_id).to eq(dossier.revision_id)
|
||||
expect(DeletedDossier.where(dossier_id: dossier.id).first.user_id).to eq(dossier.user_id)
|
||||
expect(DeletedDossier.where(dossier_id: dossier.id).first.groupe_instructeur_id).to eq(dossier.groupe_instructeur_id)
|
||||
it 'does not add a record into deleted_dossiers table' do
|
||||
expect(DeletedDossier.where(dossier_id: dossier.id).count).to eq(0)
|
||||
end
|
||||
|
||||
it 'discard the dossier' do
|
||||
|
@ -804,6 +801,11 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
it 'does not discard the dossier' do
|
||||
expect(dossier.reload.hidden_at).to eq(nil)
|
||||
end
|
||||
|
||||
it 'fill hidden by reason' do
|
||||
expect(dossier.reload.hidden_by_reason).not_to eq(nil)
|
||||
expect(dossier.reload.hidden_by_reason).to eq("instructeur_request")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the instructeur want to delete a dossier without a decision' do
|
||||
|
|
|
@ -1007,7 +1007,7 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
shared_examples_for "the dossier can not be deleted" do
|
||||
it "doesn’t notify the deletion" do
|
||||
expect(DossierMailer).not_to receive(:notify_deletion_to_administration)
|
||||
expect(DossierMailer).not_to receive(:notify_en_construction_deletion_to_administration)
|
||||
subject
|
||||
end
|
||||
|
||||
|
@ -1022,17 +1022,23 @@ describe Users::DossiersController, type: :controller do
|
|||
let(:dossier) { create(:dossier, :en_construction, user: user, autorisation_donnees: true) }
|
||||
|
||||
it "notifies the user and the admin of the deletion" do
|
||||
expect(DossierMailer).to receive(:notify_deletion_to_administration).with(kind_of(DeletedDossier), dossier.procedure.administrateurs.first.email).and_return(double(deliver_later: nil))
|
||||
expect(DossierMailer).to receive(:notify_en_construction_deletion_to_administration).with(kind_of(Dossier), dossier.procedure.administrateurs.first.email).and_return(double(deliver_later: nil))
|
||||
subject
|
||||
end
|
||||
|
||||
it "hide the dossier and create a deleted dossier" do
|
||||
it "hide the dossier and does not create a deleted dossier" do
|
||||
procedure = dossier.procedure
|
||||
dossier_id = dossier.id
|
||||
subject
|
||||
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.count).to eq(0)
|
||||
end
|
||||
|
||||
it "fill hidden by reason" do
|
||||
subject
|
||||
expect(dossier.reload.hidden_by_reason).not_to eq(nil)
|
||||
expect(dossier.reload.hidden_by_reason).to eq("user_request")
|
||||
end
|
||||
|
||||
it { is_expected.to redirect_to(dossiers_path) }
|
||||
|
|
|
@ -8,6 +8,7 @@ RSpec.describe Cron::DiscardedDossiersDeletionJob, type: :job do
|
|||
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_column(:hidden_by_reason, "user_request")
|
||||
|
||||
Cron::DiscardedDossiersDeletionJob.perform_now
|
||||
end
|
||||
|
@ -42,7 +43,6 @@ RSpec.describe Cron::DiscardedDossiersDeletionJob, type: :job do
|
|||
|
||||
context 'not hidden' do
|
||||
let(:hidden_at) { nil }
|
||||
|
||||
include_examples "does not delete"
|
||||
end
|
||||
|
||||
|
@ -60,7 +60,6 @@ RSpec.describe Cron::DiscardedDossiersDeletionJob, type: :job do
|
|||
|
||||
context 'hidden long ago' do
|
||||
let(:hidden_at) { 1.week.ago - 1.hour }
|
||||
|
||||
include_examples "does delete"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -794,7 +794,6 @@ 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 }
|
||||
|
||||
|
@ -811,10 +810,6 @@ describe Dossier do
|
|||
expect(dossier.discarded?).to be_truthy
|
||||
end
|
||||
|
||||
it 'do not creates a DeletedDossier record' do
|
||||
expect(deleted_dossier).to be_nil
|
||||
end
|
||||
|
||||
it 'do not records the operation in the log' do
|
||||
expect(last_operation).to be_nil
|
||||
end
|
||||
|
@ -826,14 +821,6 @@ describe Dossier do
|
|||
expect(dossier.hidden_by_user_at).to be_present
|
||||
end
|
||||
|
||||
it 'creates a DeletedDossier record' do
|
||||
expect(deleted_dossier.reason).to eq DeletedDossier.reasons.fetch(reason)
|
||||
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 'records the operation in the log' do
|
||||
expect(last_operation.operation).to eq("supprimer")
|
||||
expect(last_operation.automatic_operation?).to be_falsey
|
||||
|
@ -846,19 +833,6 @@ describe Dossier do
|
|||
non_following_instructeur.groupe_instructeurs << dossier.procedure.defaut_groupe_instructeur
|
||||
non_following_instructeur
|
||||
end
|
||||
|
||||
it 'notifies the following instructeurs' 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_instructeurs.first.email)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are no following instructeurs' 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.administrateurs.first.email)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when dossier is brouillon' do
|
||||
|
@ -894,6 +868,19 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'termine' do
|
||||
let(:dossier) { create(:dossier, state: "accepte", hidden_by_administration_at: 1.hour.ago) }
|
||||
before { subject }
|
||||
|
||||
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
|
||||
|
||||
describe 'webhook' do
|
||||
|
|
|
@ -310,7 +310,7 @@ 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_present
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_nil
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_brouillon)).to be_nil
|
||||
expect(User.find_by(id: user.id)).to be_nil
|
||||
end
|
||||
|
@ -324,7 +324,7 @@ describe User, type: :model do
|
|||
dossier_to_discard.discard_and_keep_track!(super_admin, :user_request)
|
||||
user.delete_and_keep_track_dossiers(super_admin)
|
||||
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
|
||||
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_nil
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue