You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.0 KiB
73 lines
2.0 KiB
require "rails_helper" |
|
|
|
RSpec.describe BulkUpload::Processor do |
|
subject(:processor) { described_class.new(bulk_upload:) } |
|
|
|
let(:bulk_upload) { create(:bulk_upload, :lettings) } |
|
|
|
describe "#call" do |
|
context "when processing a bulk upload with errors" do |
|
let(:mock_downloader) do |
|
instance_double( |
|
BulkUpload::Downloader, |
|
call: nil, |
|
path: file_fixture("2022_23_lettings_bulk_upload.csv"), |
|
delete_local_file!: nil, |
|
) |
|
end |
|
|
|
it "persist the validation errors" do |
|
allow(BulkUpload::Downloader).to receive(:new).with(bulk_upload:).and_return(mock_downloader) |
|
|
|
expect { processor.call }.to change(BulkUploadError, :count) |
|
end |
|
|
|
it "deletes the local file afterwards" do |
|
allow(BulkUpload::Downloader).to receive(:new).with(bulk_upload:).and_return(mock_downloader) |
|
|
|
processor.call |
|
|
|
expect(mock_downloader).to have_received(:delete_local_file!) |
|
end |
|
end |
|
|
|
context "when processing a bulk with perfect data" do |
|
let(:path) { file_fixture("2022_23_lettings_bulk_upload.csv") } |
|
|
|
let(:mock_downloader) do |
|
instance_double( |
|
BulkUpload::Downloader, |
|
call: nil, |
|
path:, |
|
delete_local_file!: nil, |
|
) |
|
end |
|
|
|
let(:mock_validator) do |
|
instance_double( |
|
BulkUpload::Lettings::Validator, |
|
call: nil, |
|
create_logs?: true, |
|
) |
|
end |
|
|
|
let(:mock_creator) do |
|
instance_double( |
|
BulkUpload::Lettings::LogCreator, |
|
call: nil, |
|
path:, |
|
) |
|
end |
|
|
|
it "creates logs" do |
|
allow(BulkUpload::Downloader).to receive(:new).with(bulk_upload:).and_return(mock_downloader) |
|
allow(BulkUpload::Lettings::Validator).to receive(:new).and_return(mock_validator) |
|
allow(BulkUpload::Lettings::LogCreator).to receive(:new).with(bulk_upload:, path:).and_return(mock_creator) |
|
|
|
processor.call |
|
|
|
expect(mock_creator).to have_received(:call) |
|
end |
|
end |
|
end |
|
end
|
|
|