-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from ifad/chore/fix-specs
Fix sidekiq workers specs
- Loading branch information
Showing
5 changed files
with
104 additions
and
97 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.