Browse Source

Empty bulk upload row parsing (#2638)

* empty

* Add stripped_row back

* Skip empty rows
pull/2639/head
kosiakkatrina 4 months ago committed by GitHub
parent
commit
c3bfadfe7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      app/services/bulk_upload/lettings/year2024/csv_parser.rb
  2. 6
      app/services/bulk_upload/sales/year2024/csv_parser.rb
  3. 5
      spec/services/bulk_upload/lettings/year2024/csv_parser_spec.rb
  4. 5
      spec/services/bulk_upload/sales/year2024/csv_parser_spec.rb

7
app/services/bulk_upload/lettings/year2024/csv_parser.rb

@ -30,12 +30,15 @@ class BulkUpload::Lettings::Year2024::CsvParser
end
def row_parsers
@row_parsers ||= body_rows.map do |row|
@row_parsers ||= body_rows.map { |row|
next if row.empty?
stripped_row = row[col_offset..]
hash = Hash[field_numbers.zip(stripped_row)]
BulkUpload::Lettings::Year2024::RowParser.new(hash)
end
}.compact
end
def body_rows

6
app/services/bulk_upload/sales/year2024/csv_parser.rb

@ -30,12 +30,14 @@ class BulkUpload::Sales::Year2024::CsvParser
end
def row_parsers
@row_parsers ||= body_rows.map do |row|
@row_parsers ||= body_rows.map { |row|
next if row.empty?
stripped_row = row[col_offset..]
hash = Hash[field_numbers.zip(stripped_row)]
BulkUpload::Sales::Year2024::RowParser.new(hash)
end
}.compact
end
def body_rows

5
spec/services/bulk_upload/lettings/year2024/csv_parser_spec.rb

@ -41,6 +41,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::CsvParser do
file.write("Duplicate check field?\n")
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2024_field_numbers_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2024_csv_row)
file.write("\n")
file.rewind
end
@ -52,6 +53,10 @@ RSpec.describe BulkUpload::Lettings::Year2024::CsvParser do
it "parses csv correctly" do
expect(service.row_parsers[0].field_13).to eql(log.tenancycode)
end
it "does not parse the last empty row" do
expect(service.row_parsers.count).to eq(1)
end
end
context "when parsing csv with headers in arbitrary order" do

5
spec/services/bulk_upload/sales/year2024/csv_parser_spec.rb

@ -17,6 +17,7 @@ RSpec.describe BulkUpload::Sales::Year2024::CsvParser do
file.write("Duplicate check field?\n")
file.write(BulkUpload::SalesLogToCsv.new(log:).default_2024_field_numbers_row)
file.write(BulkUpload::SalesLogToCsv.new(log:).to_2024_csv_row)
file.write("\n")
file.rewind
end
@ -32,6 +33,10 @@ RSpec.describe BulkUpload::Sales::Year2024::CsvParser do
it "counts the number of valid field numbers correctly" do
expect(service).to be_correct_field_count
end
it "does not parse the last empty row" do
expect(service.row_parsers.count).to eq(1)
end
end
context "when parsing csv with headers in arbitrary order" do

Loading…
Cancel
Save