2021-10-04 12:17:07 +02:00
|
|
|
describe Manager::ProceduresController, type: :controller do
|
2020-11-05 15:09:11 +01:00
|
|
|
let(:super_admin) { create :super_admin }
|
2022-08-10 16:25:50 +02:00
|
|
|
let(:administrateur) { create(:administrateur, email: super_admin.email) }
|
|
|
|
let(:autre_administrateur) { create(:administrateur) }
|
2020-11-05 15:09:11 +01:00
|
|
|
before { sign_in super_admin }
|
2020-03-26 17:35:50 +01:00
|
|
|
|
2018-01-10 16:46:12 +01:00
|
|
|
describe '#whitelist' do
|
2020-03-26 09:08:52 +01:00
|
|
|
let(:procedure) { create(:procedure) }
|
2018-01-10 16:46:12 +01:00
|
|
|
|
|
|
|
before do
|
2018-01-23 18:16:44 +01:00
|
|
|
post :whitelist, params: { id: procedure.id }
|
2018-01-10 16:46:12 +01:00
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
2020-03-26 17:35:50 +01:00
|
|
|
it { expect(procedure.whitelisted?).to be_truthy }
|
2018-01-10 16:46:12 +01:00
|
|
|
end
|
2020-02-07 15:35:09 +01:00
|
|
|
|
|
|
|
describe '#show' do
|
|
|
|
render_views
|
|
|
|
|
2020-08-27 19:56:48 +02:00
|
|
|
let(:procedure) { create(:procedure, :published, :with_repetition) }
|
2020-02-07 15:35:09 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
get :show, params: { id: procedure.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.body).to include('sub type de champ') }
|
|
|
|
end
|
2020-03-05 12:57:28 +01:00
|
|
|
|
2020-03-26 09:08:52 +01:00
|
|
|
describe '#discard' do
|
2022-01-12 11:31:05 +01:00
|
|
|
let(:dossier) { create(:dossier, :accepte) }
|
2020-03-26 17:35:50 +01:00
|
|
|
let(:procedure) { dossier.procedure }
|
2020-03-26 09:08:52 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
post :discard, params: { id: procedure.id }
|
|
|
|
procedure.reload
|
2020-03-26 17:35:50 +01:00
|
|
|
dossier.reload
|
2020-03-26 09:08:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure.discarded?).to be_truthy }
|
2022-01-12 11:31:05 +01:00
|
|
|
it { expect(dossier.hidden_by_administration?).to be_truthy }
|
2020-03-26 17:35:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#restore' do
|
2022-01-12 11:31:05 +01:00
|
|
|
let(:dossier) { create(:dossier, :accepte, :with_individual) }
|
2020-03-26 17:35:50 +01:00
|
|
|
let(:procedure) { dossier.procedure }
|
|
|
|
|
|
|
|
before do
|
2020-11-05 15:09:11 +01:00
|
|
|
procedure.discard_and_keep_track!(super_admin)
|
2020-03-26 17:35:50 +01:00
|
|
|
|
|
|
|
post :restore, params: { id: procedure.id }
|
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure.kept?).to be_truthy }
|
2022-01-12 11:31:05 +01:00
|
|
|
it { expect(dossier.hidden_by_administration?).to be_falsey }
|
2020-03-26 09:08:52 +01:00
|
|
|
end
|
|
|
|
|
2020-03-05 12:57:28 +01:00
|
|
|
describe '#index' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
context 'sort by dossiers' do
|
2020-03-26 17:35:50 +01:00
|
|
|
let!(:dossier) { create(:dossier) }
|
|
|
|
|
2020-03-05 12:57:28 +01:00
|
|
|
before do
|
2021-05-05 21:34:57 +02:00
|
|
|
get :index, params: { procedure: { direction: :asc, order: :dossiers } }
|
2020-03-05 12:57:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.body).to include('1 dossier') }
|
|
|
|
end
|
|
|
|
end
|
2022-08-10 16:25:50 +02:00
|
|
|
|
|
|
|
describe '#delete_administrateur' do
|
|
|
|
let(:procedure) { create(:procedure, :with_service, administrateurs: [administrateur, autre_administrateur]) }
|
2022-09-13 08:45:36 +02:00
|
|
|
let(:administrateur) { create(:administrateur, email: super_admin.email) }
|
2022-08-10 16:25:50 +02:00
|
|
|
|
2022-09-13 08:45:36 +02:00
|
|
|
subject(:delete_request) { put :delete_administrateur, params: { id: procedure.id } }
|
|
|
|
|
|
|
|
it "removes the current administrateur from the procedure" do
|
|
|
|
delete_request
|
|
|
|
expect(procedure.administrateurs).to eq([autre_administrateur])
|
2022-08-10 16:25:50 +02:00
|
|
|
end
|
|
|
|
|
2022-09-13 08:45:36 +02:00
|
|
|
context 'when the current administrateur has been added as instructeur too' do
|
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
let(:administrateur) { create(:administrateur, email: super_admin.email, instructeur: instructeur) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.groupe_instructeurs.map do |groupe_instructeur|
|
|
|
|
instructeur.assign_to.create!(groupe_instructeur: groupe_instructeur, manager: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "removes the instructeur from the procedure" do
|
|
|
|
delete_request
|
|
|
|
instructeur.groupe_instructeurs.each do |groupe_instructeur|
|
|
|
|
expect(groupe_instructeur.instructeurs).not_to include(instructeur)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-08-10 16:25:50 +02:00
|
|
|
end
|
2018-01-10 16:46:12 +01:00
|
|
|
end
|