2022-06-23 13:51:58 +02:00
|
|
|
describe Administrateurs::ArchivesController, type: :controller do
|
2024-06-01 22:50:48 +02:00
|
|
|
let(:admin) { administrateurs(:default_admin) }
|
2022-07-21 13:44:21 +02:00
|
|
|
let(:procedure) { create :procedure, groupe_instructeurs: [groupe_instructeur1, groupe_instructeur2] }
|
2022-06-23 13:51:58 +02:00
|
|
|
let(:groupe_instructeur1) { create(:groupe_instructeur) }
|
|
|
|
let(:groupe_instructeur2) { create(:groupe_instructeur) }
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
subject { get :index, params: { procedure_id: procedure.id } }
|
|
|
|
|
|
|
|
context 'when logged out' do
|
|
|
|
it { is_expected.to have_http_status(302) }
|
|
|
|
end
|
2022-07-21 13:44:21 +02:00
|
|
|
|
|
|
|
context 'when logged in as administrateur_procedure.manager=false' do
|
|
|
|
let(:manager) { false }
|
2022-06-23 13:51:58 +02:00
|
|
|
before do
|
2024-06-01 22:50:48 +02:00
|
|
|
admin.administrateurs_procedures.where(procedure:).update_all(manager:)
|
2022-06-23 13:51:58 +02:00
|
|
|
sign_in(admin.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(200) }
|
|
|
|
|
|
|
|
it 'use all procedure.groupe_instructeurs' do
|
2022-10-25 14:27:51 +02:00
|
|
|
expect(Archive).to receive(:for_groupe_instructeur).and_return([])
|
2022-06-23 13:51:58 +02:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
2022-07-21 13:44:21 +02:00
|
|
|
context 'when logged in as administrateur_procedure.manager=true' do
|
|
|
|
let(:manager) { true }
|
|
|
|
|
|
|
|
before do
|
2024-06-01 22:50:48 +02:00
|
|
|
admin.administrateurs_procedures.where(procedure:).update_all(manager:)
|
2022-07-21 13:44:21 +02:00
|
|
|
sign_in(admin.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(403) }
|
|
|
|
end
|
2022-06-23 13:51:58 +02:00
|
|
|
end
|
2022-07-21 13:44:21 +02:00
|
|
|
|
2022-06-23 13:51:58 +02:00
|
|
|
describe 'GET #create' do
|
|
|
|
subject { post :create, params: { procedure_id: procedure.id, month: '22-06', type: 'monthly' } }
|
|
|
|
|
|
|
|
context 'when logged out' do
|
|
|
|
it { is_expected.to have_http_status(302) }
|
|
|
|
end
|
2022-07-21 13:44:21 +02:00
|
|
|
|
|
|
|
context 'when logged in in as administrateur_procedure.manager=false' do
|
|
|
|
let(:manager) { false }
|
|
|
|
|
2022-06-23 13:51:58 +02:00
|
|
|
before do
|
2024-06-01 22:50:48 +02:00
|
|
|
admin.administrateurs_procedures.where(procedure:).update_all(manager:)
|
2022-06-23 13:51:58 +02:00
|
|
|
sign_in(admin.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'enqueue the creation job' do
|
|
|
|
expect { subject }.to have_enqueued_job(ArchiveCreationJob).with(procedure, an_instance_of(Archive), admin)
|
2024-06-01 22:50:48 +02:00
|
|
|
expect(subject).to redirect_to(admin_procedure_archives_path(procedure))
|
2022-06-23 13:51:58 +02:00
|
|
|
end
|
|
|
|
end
|
2022-07-21 13:44:21 +02:00
|
|
|
|
|
|
|
context 'when logged in in as administrateur_procedure.manager=true' do
|
|
|
|
let(:manager) { true }
|
|
|
|
|
|
|
|
before do
|
2024-06-01 22:50:48 +02:00
|
|
|
admin.administrateurs_procedures.where(procedure:).update_all(manager:)
|
2022-07-21 13:44:21 +02:00
|
|
|
sign_in(admin.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(403) }
|
|
|
|
it 'does not enqueue the creation job' do
|
|
|
|
expect { subject }.not_to have_enqueued_job(ArchiveCreationJob)
|
|
|
|
end
|
|
|
|
end
|
2022-06-23 13:51:58 +02:00
|
|
|
end
|
|
|
|
end
|