Submit social housing lettings and sales data (CORE)
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.

97 lines
2.7 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,
CLDC-1779 Bulk upload lettings validation (#1148) * able to view lettings bulk upload errors * fix linting * call service correctly in test * add bulk upload sales questions mapping * appease linter * bulk upload error shows correct question - depending on log type it will show relevant question for the field concerned * improve namespacing of classes * add job to process bulk uploads * move validation from parser to model * add validations for field_1 * add validation for field_4 * pending tests for field_4 * convert field_mapping to array of hashes * validate nulls based on form question * actually load forms when toggling between forms * validate null for startdate * row parser has access to bulk upload * csv upload validates first form section * add postcode validation * Refactor error mappings for row parser * Add unittype question * Fix null error setting and add builtype * add wchair to bulk upload * Add beds to bulk upload * Add joint to bulk upload * Add startertenancy to the bulk upload * Add tenancy for bulk upload * Add declaration to the bulk upload * Add age1 and age1_known to bulk upload * add ages to bulk upload * add sex1 to bulk upload * add ethnic_group and ethnic to bulk upload * add national to bulk upload * add ecstat1 to bulk upload * add military related fields to bulk upload * add preg_occ to bulk upload * add housingneeds to bulk upload * add illness to bulk upload * add layear to bulk upload * add waityear to bulk upload * add reason to bulk upload * add prevten to bulk upload * add homeless to bulk upload * add previous postcode to bulk upload * add reasonable preferences to bulk upload * add allocations system to bulk upload * add referral to bulk upload * add net_income_known to bulk upload * add hb to bulk upload * add benefits to bulk upload * add rent fields to bulk upload * add hhmemb to bulk upload * use 2022 csv fixtures for bulk upload * fix renewal mapping for bulk upload * placeholder test for bulk upload validation * fix bulk upload mapping for homeless field * fix leftreg mapping for bulk upload * fix user associations in bulk upload tests * add gender fields for bulk upload * add ecstatN fields to bulk upload * add #relatN fields to bulk upload * extract old_visible_id in factory to trait * map net_income_known correctly for bulk upload * fix income bugs for bulk upload * add unitletas to bulk upload * add #rsnvac to bulk upload * add #sheltered to bulk upload * add illness fields to bulk upload * add #irproduct_other to bulk upload * infer renewal from rsnvac for bulk upload * add #tenancyother to bulk upload * add #tenancylength to bulk upload * bulk upload earnings accepts pennies but rounds * add #reasonother to bulk upload * fix mapping of #ppcodenk for bulk upload * add #household_charge to bulk upload * add #chcharge to bulk upload * add #tcharge to bulk upload * add #supcharg to bulk upload * add pscharge to bulk upload * add #scharge to bulk upload * use case statement for bulk upload allocation * add offered to bulk upload * add propcode to bulk upload * add major repair fields to bulk upload * add #voiddate to bulk upload * support YY year format for bulk upload * test postcode strips whitespace for bulk upload * add #la to bulk upload * add previous la to bulk upload * fix failing test * remove duplicate line from rebase * add first time social housing to bulk upload * make methods private * fix field_4 validation for bulk upload - the null check was inverted by mistake Co-authored-by: Kat <katrina@kosiak.co.uk>
2 years ago
path: file_fixture("2022_23_lettings_bulk_upload.csv"),
delete_local_file!: nil,
)
end
before do
allow(BulkUpload::Downloader).to receive(:new).with(bulk_upload:).and_return(mock_downloader)
end
it "persist the validation errors" do
CLDC-1779 Bulk upload lettings validation (#1148) * able to view lettings bulk upload errors * fix linting * call service correctly in test * add bulk upload sales questions mapping * appease linter * bulk upload error shows correct question - depending on log type it will show relevant question for the field concerned * improve namespacing of classes * add job to process bulk uploads * move validation from parser to model * add validations for field_1 * add validation for field_4 * pending tests for field_4 * convert field_mapping to array of hashes * validate nulls based on form question * actually load forms when toggling between forms * validate null for startdate * row parser has access to bulk upload * csv upload validates first form section * add postcode validation * Refactor error mappings for row parser * Add unittype question * Fix null error setting and add builtype * add wchair to bulk upload * Add beds to bulk upload * Add joint to bulk upload * Add startertenancy to the bulk upload * Add tenancy for bulk upload * Add declaration to the bulk upload * Add age1 and age1_known to bulk upload * add ages to bulk upload * add sex1 to bulk upload * add ethnic_group and ethnic to bulk upload * add national to bulk upload * add ecstat1 to bulk upload * add military related fields to bulk upload * add preg_occ to bulk upload * add housingneeds to bulk upload * add illness to bulk upload * add layear to bulk upload * add waityear to bulk upload * add reason to bulk upload * add prevten to bulk upload * add homeless to bulk upload * add previous postcode to bulk upload * add reasonable preferences to bulk upload * add allocations system to bulk upload * add referral to bulk upload * add net_income_known to bulk upload * add hb to bulk upload * add benefits to bulk upload * add rent fields to bulk upload * add hhmemb to bulk upload * use 2022 csv fixtures for bulk upload * fix renewal mapping for bulk upload * placeholder test for bulk upload validation * fix bulk upload mapping for homeless field * fix leftreg mapping for bulk upload * fix user associations in bulk upload tests * add gender fields for bulk upload * add ecstatN fields to bulk upload * add #relatN fields to bulk upload * extract old_visible_id in factory to trait * map net_income_known correctly for bulk upload * fix income bugs for bulk upload * add unitletas to bulk upload * add #rsnvac to bulk upload * add #sheltered to bulk upload * add illness fields to bulk upload * add #irproduct_other to bulk upload * infer renewal from rsnvac for bulk upload * add #tenancyother to bulk upload * add #tenancylength to bulk upload * bulk upload earnings accepts pennies but rounds * add #reasonother to bulk upload * fix mapping of #ppcodenk for bulk upload * add #household_charge to bulk upload * add #chcharge to bulk upload * add #tcharge to bulk upload * add #supcharg to bulk upload * add pscharge to bulk upload * add #scharge to bulk upload * use case statement for bulk upload allocation * add offered to bulk upload * add propcode to bulk upload * add major repair fields to bulk upload * add #voiddate to bulk upload * support YY year format for bulk upload * test postcode strips whitespace for bulk upload * add #la to bulk upload * add previous la to bulk upload * fix failing test * remove duplicate line from rebase * add first time social housing to bulk upload * make methods private * fix field_4 validation for bulk upload - the null check was inverted by mistake Co-authored-by: Kat <katrina@kosiak.co.uk>
2 years ago
expect { processor.call }.to change(BulkUploadError, :count)
end
it "deletes the local file afterwards" do
processor.call
expect(mock_downloader).to have_received(:delete_local_file!)
end
it "does not send success email" do
allow(BulkUploadMailer).to receive(:send_bulk_upload_complete_mail).and_call_original
processor.call
expect(BulkUploadMailer).not_to have_received(:send_bulk_upload_complete_mail)
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
before 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)
end
it "creates logs" do
processor.call
expect(mock_creator).to have_received(:call)
end
it "sends success email" do
mail_double = instance_double("ActionMailer::MessageDelivery", deliver_later: nil)
allow(BulkUploadMailer).to receive(:send_bulk_upload_complete_mail).and_return(mail_double)
create(:lettings_log, :completed, bulk_upload:)
processor.call
expect(BulkUploadMailer).to have_received(:send_bulk_upload_complete_mail)
expect(mail_double).to have_received(:deliver_later)
end
end
end
end