Browse Source

bulk upload errors not referencing correct cells (#1424)

- this is to handle different years where data is located in different
  columns
pull/1426/head
Phil Lee 2 years ago committed by GitHub
parent
commit
406215037f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      app/services/bulk_upload/lettings/validator.rb
  2. 8
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  3. 8
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  4. 40
      spec/services/bulk_upload/lettings/validator_spec.rb

10
app/services/bulk_upload/lettings/validator.rb

@ -24,14 +24,16 @@ class BulkUpload::Lettings::Validator
row = index + row_offset + 1 row = index + row_offset + 1
row_parser.errors.each do |error| row_parser.errors.each do |error|
col = csv_parser.column_for_field(error.attribute.to_s)
bulk_upload.bulk_upload_errors.create!( bulk_upload.bulk_upload_errors.create!(
field: error.attribute, field: error.attribute,
error: error.message, error: error.message,
tenant_code: row_parser.field_7, tenant_code: row_parser.tenant_code,
property_ref: row_parser.field_100, property_ref: row_parser.property_ref,
row:, row:,
cell: "#{cols[field_number_for_attribute(error.attribute) - col_offset + 1]}#{row}", cell: "#{col}#{row}",
col: csv_parser.column_for_field(error.attribute.to_s), col:,
category: error.options[:category], category: error.options[:category],
) )
end end

8
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -372,6 +372,14 @@ class BulkUpload::Lettings::Year2022::RowParser
block_log_creation block_log_creation
end end
def tenant_code
field_7
end
def property_ref
field_100
end
private private
def validate_location_related def validate_location_related

8
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -375,6 +375,14 @@ class BulkUpload::Lettings::Year2023::RowParser
block_log_creation block_log_creation
end end
def tenant_code
field_13
end
def property_ref
field_14
end
private private
def validate_needs_type_present def validate_needs_type_present

40
spec/services/bulk_upload/lettings/validator_spec.rb

@ -71,6 +71,46 @@ RSpec.describe BulkUpload::Lettings::Validator do
end end
end end
context "with arbitrary ordered 23/24 csv" do
let(:bulk_upload) { create(:bulk_upload, user:, year: 2023) }
let(:log) { build(:lettings_log, :completed) }
let(:file) { Tempfile.new }
let(:path) { file.path }
let(:seed) { 321 }
around do |example|
FormHandler.instance.use_real_forms!
example.run
FormHandler.instance.use_fake_forms!
end
before do
file.write(BulkUpload::LogToCsv.new(log:, line_ending: "\r\n").default_2023_field_numbers_row(seed:))
file.write(BulkUpload::LogToCsv.new(log:, line_ending: "\r\n").to_2023_csv_row(seed:))
file.close
end
it "creates validation errors" do
expect { validator.call }.to change(BulkUploadError, :count)
end
it "create validation error with correct values" do
validator.call
error = BulkUploadError.find_by(field: "field_5")
expect(error.field).to eql("field_5")
expect(error.error).to eql("You must answer letting type")
expect(error.tenant_code).to eql(log.tenancycode)
expect(error.property_ref).to eql(log.propcode)
expect(error.row).to eql("2")
expect(error.cell).to eql("DD2")
expect(error.col).to eql("DD")
end
end
context "with unix line endings" do context "with unix line endings" do
let(:fixture_path) { file_fixture("2022_23_lettings_bulk_upload.csv") } let(:fixture_path) { file_fixture("2022_23_lettings_bulk_upload.csv") }
let(:file) { Tempfile.new } let(:file) { Tempfile.new }

Loading…
Cancel
Save