2021-04-29 17:29:47 +02:00
|
|
|
describe Instructeurs::ArchivesController, type: :controller do
|
2022-07-21 15:18:07 +02:00
|
|
|
let(:procedure1) { create(:procedure, :published, groupe_instructeurs: [assign_to.groupe_instructeur]) }
|
2021-04-29 17:29:47 +02:00
|
|
|
let(:procedure2) { create(:procedure, :published, groupe_instructeurs: [gi2]) }
|
2022-07-21 15:18:07 +02:00
|
|
|
let!(:instructeur) { create(:instructeur, groupe_instructeurs: [gi2]) }
|
|
|
|
let!(:archive1) { create(:archive, :generated, groupe_instructeurs: [assign_to.groupe_instructeur]) }
|
2021-04-29 17:29:47 +02:00
|
|
|
let!(:archive2) { create(:archive, :generated, groupe_instructeurs: [gi2]) }
|
2022-07-21 15:18:07 +02:00
|
|
|
let!(:assign_to) { create(:assign_to, instructeur: instructeur, groupe_instructeur: build(:groupe_instructeur), manager: manager) }
|
2021-04-29 17:29:47 +02:00
|
|
|
let(:gi2) { create(:groupe_instructeur) }
|
|
|
|
|
2022-07-21 15:27:21 +02:00
|
|
|
before do
|
2021-04-29 17:29:47 +02:00
|
|
|
sign_in(instructeur.user)
|
2022-07-21 15:27:21 +02:00
|
|
|
end
|
|
|
|
after { Timecop.return }
|
2021-04-29 17:29:47 +02:00
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
before do
|
|
|
|
create_dossier_for_month(procedure1, 2021, 3)
|
|
|
|
create_dossier_for_month(procedure1, 2021, 3)
|
|
|
|
create_dossier_for_month(procedure1, 2021, 2)
|
|
|
|
Timecop.freeze(Time.zone.local(2021, 3, 5))
|
|
|
|
end
|
2022-07-21 15:27:21 +02:00
|
|
|
subject { get :index, params: { procedure_id: procedure1.id } }
|
2022-07-21 15:18:07 +02:00
|
|
|
|
|
|
|
context 'signed in not as manager' do
|
2022-07-21 15:27:21 +02:00
|
|
|
let(:manager) { false }
|
2021-04-29 17:29:47 +02:00
|
|
|
|
2022-07-21 15:18:07 +02:00
|
|
|
it { is_expected.to have_http_status(:success) }
|
|
|
|
it 'assigns archives' do
|
|
|
|
subject
|
|
|
|
expect(assigns(:archives)).to eq([archive1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'signed in as manager' do
|
2022-07-21 15:27:21 +02:00
|
|
|
let(:manager) { true }
|
2022-07-21 15:18:07 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(instructeur.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(:forbidden) }
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#create' do
|
|
|
|
let(:subject) do
|
2021-09-02 23:35:36 +02:00
|
|
|
post :create, params: { procedure_id: procedure1.id, type: 'monthly', month: month }
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
|
|
|
|
2022-07-21 15:18:07 +02:00
|
|
|
let(:month) { '21-03' }
|
|
|
|
let(:date_month) { Date.strptime(month, "%Y-%m") }
|
|
|
|
|
|
|
|
context 'signed in not as manager' do
|
2022-07-21 15:27:21 +02:00
|
|
|
let(:manager) { false }
|
2022-07-21 15:18:07 +02:00
|
|
|
|
|
|
|
it "performs archive creation job" do
|
|
|
|
expect { subject }.to have_enqueued_job(ArchiveCreationJob).with(procedure1, an_instance_of(Archive), instructeur)
|
|
|
|
expect(flash.notice).to include("Votre demande a été prise en compte")
|
|
|
|
end
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
2022-07-21 15:18:07 +02:00
|
|
|
|
|
|
|
context 'signed in as manager' do
|
2022-07-21 15:27:21 +02:00
|
|
|
let(:manager) { true }
|
2022-07-21 15:18:07 +02:00
|
|
|
|
|
|
|
it { is_expected.to have_http_status(:forbidden) }
|
|
|
|
end
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_dossier_for_month(procedure, year, month)
|
|
|
|
Timecop.freeze(Time.zone.local(year, month, 5))
|
|
|
|
create(:dossier, :accepte, :with_attestation, procedure: procedure)
|
|
|
|
end
|
|
|
|
end
|