2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-07 18:15:48 +02:00
|
|
|
describe Archive do
|
2021-04-29 17:29:47 +02:00
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
|
|
|
before { Timecop.freeze(Time.zone.now) }
|
|
|
|
after { Timecop.return }
|
|
|
|
|
2022-07-27 10:32:54 +02:00
|
|
|
let!(:archive) { create(:archive, job_status: :pending) }
|
2021-04-29 17:29:47 +02:00
|
|
|
|
|
|
|
describe 'scopes' do
|
|
|
|
describe 'staled' do
|
2022-07-27 10:32:54 +02:00
|
|
|
let!(:recent_archive) { create(:archive, job_status: :pending) }
|
|
|
|
let!(:staled_archive_still_pending) { create(:archive, job_status: :pending, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
|
|
|
let!(:staled_archive_still_failed) { create(:archive, job_status: :failed, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
|
|
|
let!(:staled_archive_still_generated) { create(:archive, job_status: :generated, updated_at: (Archive::RETENTION_DURATION + 2).days.ago) }
|
2021-04-29 17:29:47 +02:00
|
|
|
|
|
|
|
subject do
|
2022-07-07 18:15:48 +02:00
|
|
|
Archive.stale(Archive::RETENTION_DURATION)
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
|
|
|
|
2022-07-07 18:15:48 +02:00
|
|
|
it { is_expected.to match_array([staled_archive_still_failed, staled_archive_still_generated]) }
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
2022-07-27 10:32:54 +02:00
|
|
|
|
|
|
|
describe 'stuck' do
|
|
|
|
let!(:recent_archive) { create(:archive, job_status: :pending) }
|
|
|
|
let!(:staled_archive_still_pending) { create(:archive, job_status: :pending, updated_at: (Archive::MAX_DUREE_GENERATION + 2).days.ago) }
|
|
|
|
let!(:staled_archive_still_failed) { create(:archive, job_status: :failed, updated_at: (Archive::MAX_DUREE_GENERATION + 2).days.ago) }
|
|
|
|
let!(:staled_archive_still_generated) { create(:archive, job_status: :generated, updated_at: (Archive::MAX_DUREE_GENERATION + 2).days.ago) }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
Archive.stuck(Archive::MAX_DUREE_GENERATION)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match_array([staled_archive_still_pending]) }
|
|
|
|
end
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
|
|
|
|
2022-07-07 18:15:48 +02:00
|
|
|
describe '.job_status' do
|
|
|
|
it { expect(archive.job_status).to eq('pending') }
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#make_available!' do
|
|
|
|
before { archive.make_available! }
|
2022-07-07 18:15:48 +02:00
|
|
|
it { expect(archive.job_status).to eq('generated') }
|
2021-04-29 17:29:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#available?' do
|
|
|
|
subject { archive.available? }
|
|
|
|
context 'without attachment' do
|
|
|
|
let(:archive) { create(:archive, file: nil) }
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an attachment' do
|
|
|
|
context 'when the attachment was created but the process was not over' do
|
|
|
|
let(:archive) { create(:archive, :pending, file: Rack::Test::UploadedFile.new('spec/fixtures/files/file.pdf', 'application/pdf')) }
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the attachment was created but the process was not over' do
|
|
|
|
let(:archive) { create(:archive, :generated, file: Rack::Test::UploadedFile.new('spec/fixtures/files/file.pdf', 'application/pdf')) }
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|