2022-03-30 16:19:14 +02:00
|
|
|
describe ArchiveCreationJob, type: :job do
|
|
|
|
describe 'perform' do
|
2022-07-07 18:15:48 +02:00
|
|
|
let(:archive) { create(:archive, job_status: status, groupe_instructeurs: [procedure.groupe_instructeurs.first]) }
|
2022-03-30 16:19:14 +02:00
|
|
|
let(:instructeur) { create(:instructeur) }
|
|
|
|
let(:procedure) { create(:procedure, instructeurs: [instructeur]) }
|
|
|
|
let(:job) { ArchiveCreationJob.new(procedure, archive, instructeur) }
|
|
|
|
|
|
|
|
context 'when it fails' do
|
|
|
|
let(:status) { :pending }
|
|
|
|
let(:mailer) { double('mailer', deliver_later: true) }
|
2022-06-23 13:51:58 +02:00
|
|
|
before { expect(UserMailer).not_to receive(:send_archive) }
|
2022-03-30 16:19:14 +02:00
|
|
|
|
|
|
|
it 'does not send email and forward error for retry' do
|
2022-04-08 17:07:54 +02:00
|
|
|
allow(DownloadableFileService).to receive(:download_and_zip).and_raise(StandardError, "kaboom")
|
2022-03-30 16:19:14 +02:00
|
|
|
expect { job.perform_now }.to raise_error(StandardError, "kaboom")
|
|
|
|
expect(archive.reload.failed?).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when it works' do
|
|
|
|
let(:mailer) { double('mailer', deliver_later: true) }
|
|
|
|
before do
|
2022-04-08 17:07:54 +02:00
|
|
|
allow(DownloadableFileService).to receive(:download_and_zip).and_return(true)
|
2022-06-23 13:51:58 +02:00
|
|
|
expect(UserMailer).to receive(:send_archive).and_return(mailer)
|
2022-03-30 16:19:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when archive failed previously' do
|
|
|
|
let(:status) { :failed }
|
|
|
|
it 'restarts and works from failed states' do
|
|
|
|
expect { job.perform_now }.to change { archive.reload.failed? }.from(true).to(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'when archive start from pending state' do
|
|
|
|
let(:status) { :pending }
|
|
|
|
it 'restarts and works from failed states' do
|
|
|
|
expect { job.perform_now }.to change { archive.reload.generated? }.from(false).to(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|