Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sidekiq workers specs #283

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions spec/lib/colore/sidekiq/callback_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'spec_helper'

require 'rest_client'

RSpec.describe Colore::Sidekiq::CallbackWorker do
let(:doc_key) { Colore::DocKey.new('app', '12345') }
let(:callback_url) { 'https://example.org/callback' }

before do
setup_storage
allow(Colore::C_).to receive(:storage_directory) { tmp_storage_dir }
end

after do
delete_storage
end

describe '#perform' do
it 'runs' do
allow(RestClient).to receive(:post)

described_class.new.perform doc_key.to_s, 'current', 'arglebargle.docx', 'pdf', callback_url, 250, 'foobar'

expect(RestClient).to have_received(:post).with(callback_url, an_instance_of(Hash))
end
end
end
39 changes: 39 additions & 0 deletions spec/lib/colore/sidekiq/conversion_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Colore::Sidekiq::ConversionWorker do
let(:doc_key) { Colore::DocKey.new('app', '12345') }
let(:callback_url) { 'http://foo/bar' }
let(:converter) { instance_double(Colore::Converter, convert: true) }

before do
allow(Colore::Converter).to receive(:new).and_return(converter)
allow(Colore::Sidekiq::CallbackWorker).to receive(:perform_async)
end

describe '#perform' do
it 'runs' do
described_class.new.perform doc_key.to_s, 'current', 'arglebargle.docx', 'pdf', callback_url

expect(Colore::Sidekiq::CallbackWorker).to have_received(:perform_async)
expect(converter).to have_received(:convert)
end

it 'gives up on Heathen::TaskNotFound' do
allow(converter).to receive(:convert).and_raise Heathen::TaskNotFound.new('foo', 'bar')

described_class.new.perform doc_key.to_s, 'current', 'arglebargle.docx', 'pdf', callback_url

expect(Colore::Sidekiq::CallbackWorker).to have_received(:perform_async)
end

it 'gives up on other errors' do
allow(converter).to receive(:convert).and_raise 'arglebargle'

described_class.new.perform doc_key.to_s, 'current', 'arglebargle.docx', 'pdf', callback_url

expect(Colore::Sidekiq::CallbackWorker).to have_received(:perform_async)
end
end
end
36 changes: 36 additions & 0 deletions spec/lib/colore/sidekiq/legacy_purge_worker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Colore::Sidekiq::LegacyPurgeWorker do
before do
setup_storage
allow(Colore::C_).to receive(:storage_directory) { tmp_storage_dir }
allow(Colore::C_).to receive(:legacy_purge_days).and_return(2)
end

after do
delete_storage
end

describe '#perform' do
it 'runs' do
dir = Colore::LegacyConverter.new.legacy_dir
file1 = dir.join('file1.tiff')
file2 = dir.join('file2.tiff')
file1.write('foobar')
file2.write('foobar')
described_class.new.perform
expect(file1.file?).to be true
expect(file2.file?).to be true
Timecop.freeze(Date.today + 1)
described_class.new.perform
expect(file1.file?).to be true
expect(file2.file?).to be true
Timecop.freeze(Date.today + 3)
described_class.new.perform
expect(file1.file?).to be false
expect(file2.file?).to be false
end
end
end
88 changes: 0 additions & 88 deletions spec/lib/sidekiq_workers_spec.rb

This file was deleted.