Browse Source

Refactor with split of log to CSV by log type (#1593)

# Context

- Partially related to https://digital.dclg.gov.uk/jira/browse/CLDC-2316
- Comprehending sales or lettings bulk upload CSV is enough, comprehending both simultaneously is rather challenging

# Changes

- Split out test helper class by log type ie lettings/sales
pull/1601/head
Phil Lee 2 years ago committed by GitHub
parent
commit
45128b7250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      spec/services/bulk_upload/lettings/log_creator_spec.rb
  2. 30
      spec/services/bulk_upload/lettings/validator_spec.rb
  3. 30
      spec/services/bulk_upload/lettings/year2022/csv_parser_spec.rb
  4. 30
      spec/services/bulk_upload/lettings/year2023/csv_parser_spec.rb
  5. 6
      spec/services/bulk_upload/processor_spec.rb
  6. 8
      spec/services/bulk_upload/sales/log_creator_spec.rb
  7. 34
      spec/services/bulk_upload/sales/validator_spec.rb
  8. 8
      spec/services/bulk_upload/sales/year2022/csv_parser_spec.rb
  9. 153
      spec/support/bulk_upload/lettings_log_to_csv.rb
  10. 187
      spec/support/bulk_upload/sales_log_to_csv.rb

8
spec/services/bulk_upload/lettings/log_creator_spec.rb

@ -35,9 +35,9 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
let(:log) { LettingsLog.new }
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end
@ -66,7 +66,7 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
end
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end

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

@ -50,7 +50,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
context "when file has headers" do
context "and file has extra invalid headers" do
let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LogToCsv.new(log:) }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
let(:field_numbers) { log_to_csv.default_2022_field_numbers + %w[invalid_field_number] }
let(:field_values) { log_to_csv.to_2022_row + %w[value_for_invalid_field_number] }
@ -67,7 +67,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
context "and file has too few valid headers" do
let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LogToCsv.new(log:) }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
let(:field_numbers) { log_to_csv.default_2022_field_numbers }
let(:field_values) { log_to_csv.to_2022_row }
@ -87,7 +87,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
context "and file has too many valid headers" do
let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LogToCsv.new(log:) }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
let(:field_numbers) { log_to_csv.default_2022_field_numbers + %w[23] }
let(:field_values) { log_to_csv.to_2022_row + %w[value] }
@ -138,7 +138,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
context "when file has headers" do
context "and file has extra invalid headers" do
let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LogToCsv.new(log:) }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
let(:field_numbers) { log_to_csv.default_2023_field_numbers + %w[invalid_field_number] }
let(:field_values) { log_to_csv.to_2023_row + %w[value_for_invalid_field_number] }
@ -155,7 +155,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
context "and file has too few valid headers" do
let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LogToCsv.new(log:) }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
let(:field_numbers) { log_to_csv.default_2023_field_numbers }
let(:field_values) { log_to_csv.to_2023_row }
@ -175,7 +175,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
context "and file has too many valid headers" do
let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LogToCsv.new(log:) }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
let(:field_numbers) { log_to_csv.default_2023_field_numbers + %w[23] }
let(:field_values) { log_to_csv.to_2023_row + %w[value] }
@ -233,8 +233,8 @@ RSpec.describe BulkUpload::Lettings::Validator do
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.write(BulkUpload::LettingsLogToCsv.new(log:, line_ending: "\r\n").default_2023_field_numbers_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:, line_ending: "\r\n").to_2023_csv_row(seed:))
file.close
end
@ -280,7 +280,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
let(:path) { file.path }
before do
file.write(BulkUpload::LogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
@ -322,8 +322,8 @@ RSpec.describe BulkUpload::Lettings::Validator do
let(:log_2) { build(:lettings_log, :completed, created_by: user) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0, overrides: { illness: 100 }).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0, overrides: { illness: 100 }).to_2022_csv_row)
file.close
end
@ -338,8 +338,8 @@ RSpec.describe BulkUpload::Lettings::Validator do
let(:log_2) { build(:lettings_log, :completed, renttype: 1, created_by: user) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
@ -355,7 +355,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
let(:log_1) { build(:lettings_log, :completed, renttype: 1, created_by: user, owning_organisation: unaffiliated_org) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
@ -369,7 +369,7 @@ RSpec.describe BulkUpload::Lettings::Validator do
let(:log) { build(:lettings_log, :in_progress, created_by: user, startdate: Time.zone.local(2022, 5, 1)) }
before do
file.write(BulkUpload::LogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end

30
spec/services/bulk_upload/lettings/year2022/csv_parser_spec.rb

@ -9,8 +9,8 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
context "when parsing csv with headers" do
before do
file.write(BulkUpload::LogToCsv.new(log:).default_2022_field_numbers_row)
file.write(BulkUpload::LogToCsv.new(log:).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2022_field_numbers_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2022_csv_row)
file.rewind
end
@ -27,8 +27,8 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
context "when parsing csv with headers with extra rows" do
before do
file.write("Extra row\n")
file.write(BulkUpload::LogToCsv.new(log:).default_2022_field_numbers_row)
file.write(BulkUpload::LogToCsv.new(log:).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2022_field_numbers_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2022_csv_row)
file.rewind
end
@ -46,8 +46,8 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
let(:seed) { rand }
before do
file.write(BulkUpload::LogToCsv.new(log:).default_2022_field_numbers_row(seed:))
file.write(BulkUpload::LogToCsv.new(log:).to_2022_csv_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2022_field_numbers_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2022_csv_row(seed:))
file.rewind
end
@ -63,7 +63,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
context "when parsing csv with extra invalid headers" do
let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LogToCsv.new(log:) }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
let(:field_numbers) { log_to_csv.default_2022_field_numbers + %w[invalid_field_number] }
let(:field_values) { log_to_csv.to_2022_row + %w[value_for_invalid_field_number] }
@ -84,7 +84,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
context "when parsing csv without headers" do
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end
@ -103,7 +103,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
before do
file.write(bom)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end
@ -117,7 +117,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
before do
file.write(invalid_sequence)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end
@ -129,8 +129,8 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
describe "#column_for_field", aggregate_failures: true do
context "when with headers using default ordering" do
before do
file.write(BulkUpload::LogToCsv.new(log:).default_2022_field_numbers_row)
file.write(BulkUpload::LogToCsv.new(log:).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2022_field_numbers_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2022_csv_row)
file.rewind
end
@ -142,7 +142,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
context "when without headers using default ordering" do
before do
file.write(BulkUpload::LogToCsv.new(log:).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2022_csv_row)
file.rewind
end
@ -156,8 +156,8 @@ RSpec.describe BulkUpload::Lettings::Year2022::CsvParser do
let(:seed) { 123 }
before do
file.write(BulkUpload::LogToCsv.new(log:).default_2022_field_numbers_row(seed:))
file.write(BulkUpload::LogToCsv.new(log:).to_2022_csv_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2022_field_numbers_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2022_csv_row(seed:))
file.rewind
end

30
spec/services/bulk_upload/lettings/year2023/csv_parser_spec.rb

@ -15,8 +15,8 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
file.write("Can be empty?\n")
file.write("Type of letting the question applies to\n")
file.write("Duplicate check field?\n")
file.write(BulkUpload::LogToCsv.new(log:).default_2023_field_numbers_row)
file.write(BulkUpload::LogToCsv.new(log:).to_2023_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2023_field_numbers_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2023_csv_row)
file.rewind
end
@ -39,8 +39,8 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
file.write("Can be empty?\n")
file.write("Type of letting the question applies to\n")
file.write("Duplicate check field?\n")
file.write(BulkUpload::LogToCsv.new(log:).default_2023_field_numbers_row)
file.write(BulkUpload::LogToCsv.new(log:).to_2023_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2023_field_numbers_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2023_csv_row)
file.rewind
end
@ -64,8 +64,8 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
file.write("Can be empty?\n")
file.write("Type of letting the question applies to\n")
file.write("Duplicate check field?\n")
file.write(BulkUpload::LogToCsv.new(log:).default_2023_field_numbers_row(seed:))
file.write(BulkUpload::LogToCsv.new(log:).to_2023_csv_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2023_field_numbers_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2023_csv_row(seed:))
file.rewind
end
@ -81,7 +81,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
context "when parsing csv with extra invalid headers" do
let(:seed) { rand }
let(:log_to_csv) { BulkUpload::LogToCsv.new(log:) }
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) }
let(:field_numbers) { log_to_csv.default_2023_field_numbers + %w[invalid_field_number] }
let(:field_values) { log_to_csv.to_2023_row + %w[value_for_invalid_field_number] }
@ -108,7 +108,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
context "when parsing csv without headers" do
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2023_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2023_csv_row)
file.rewind
end
@ -127,7 +127,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
before do
file.write(bom)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2023_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2023_csv_row)
file.rewind
end
@ -141,7 +141,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
before do
file.write(invalid_sequence)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2023_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2023_csv_row)
file.rewind
end
@ -159,8 +159,8 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
file.write("Can be empty?\n")
file.write("Type of letting the question applies to\n")
file.write("Duplicate check field?\n")
file.write(BulkUpload::LogToCsv.new(log:).default_2023_field_numbers_row)
file.write(BulkUpload::LogToCsv.new(log:).to_2023_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2023_field_numbers_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2023_csv_row)
file.rewind
end
@ -172,7 +172,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
context "when without headers using default ordering" do
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2023_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2023_csv_row)
file.rewind
end
@ -192,8 +192,8 @@ RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do
file.write("Can be empty?\n")
file.write("Type of letting the question applies to\n")
file.write("Duplicate check field?\n")
file.write(BulkUpload::LogToCsv.new(log:).default_2023_field_numbers_row(seed:))
file.write(BulkUpload::LogToCsv.new(log:).to_2023_csv_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_2023_field_numbers_row(seed:))
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_2023_csv_row(seed:))
file.rewind
end

6
spec/services/bulk_upload/processor_spec.rb

@ -165,7 +165,7 @@ RSpec.describe BulkUpload::Processor do
end
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
allow(BulkUpload::Downloader).to receive(:new).with(bulk_upload:).and_return(mock_downloader)
@ -213,7 +213,7 @@ RSpec.describe BulkUpload::Processor do
end
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
allow(BulkUpload::Downloader).to receive(:new).with(bulk_upload:).and_return(mock_downloader)
@ -265,7 +265,7 @@ RSpec.describe BulkUpload::Processor do
end
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
allow(BulkUpload::Downloader).to receive(:new).with(bulk_upload:).and_return(mock_downloader)

8
spec/services/bulk_upload/sales/log_creator_spec.rb

@ -35,9 +35,9 @@ RSpec.describe BulkUpload::Sales::LogCreator do
let(:log) { SalesLog.new }
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end
@ -59,7 +59,7 @@ RSpec.describe BulkUpload::Sales::LogCreator do
end
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end

34
spec/services/bulk_upload/sales/validator_spec.rb

@ -87,7 +87,7 @@ RSpec.describe BulkUpload::Sales::Validator do
let(:path) { file.path }
before do
file.write(BulkUpload::LogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
@ -129,8 +129,8 @@ RSpec.describe BulkUpload::Sales::Validator do
let(:log_2) { build(:sales_log, :completed, created_by: user) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0, overrides: { organisation_id: "random" }).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0, overrides: { organisation_id: "random" }).to_2022_csv_row)
file.close
end
@ -145,8 +145,8 @@ RSpec.describe BulkUpload::Sales::Validator do
let(:log_2) { build(:sales_log, :completed, created_by: user) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
@ -162,7 +162,7 @@ RSpec.describe BulkUpload::Sales::Validator do
let(:log_1) { build(:sales_log, :completed, created_by: user, owning_organisation: unaffiliated_org) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
@ -176,7 +176,7 @@ RSpec.describe BulkUpload::Sales::Validator do
let(:log) { build(:sales_log, created_by: user, saledate: Time.zone.local(2022, 5, 1)) }
before do
file.write(BulkUpload::LogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
@ -195,11 +195,11 @@ RSpec.describe BulkUpload::Sales::Validator do
let(:log_5) { build(:sales_log, :in_progress, created_by: user, saledate: Time.zone.local(2022, 5, 1)) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_3, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_4, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_5, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_3, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_4, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_5, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end
@ -217,11 +217,11 @@ RSpec.describe BulkUpload::Sales::Validator do
let(:log_5) { build(:sales_log, :in_progress, created_by: user, saledate: Time.zone.local(2022, 5, 1)) }
before do
file.write(BulkUpload::LogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_3, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_4, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::LogToCsv.new(log: log_5, line_ending: "\r\n", col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_1, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_2, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_3, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_4, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log: log_5, line_ending: "\r\n", col_offset: 0).to_2022_csv_row)
file.close
end

8
spec/services/bulk_upload/sales/year2022/csv_parser_spec.rb

@ -22,7 +22,7 @@ RSpec.describe BulkUpload::Sales::Year2022::CsvParser do
let(:log) { build(:sales_log, :completed) }
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end
@ -44,7 +44,7 @@ RSpec.describe BulkUpload::Sales::Year2022::CsvParser do
before do
file.write(bom)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.close
end
@ -61,7 +61,7 @@ RSpec.describe BulkUpload::Sales::Year2022::CsvParser do
before do
file.write(invalid_sequence)
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.close
end
@ -84,7 +84,7 @@ RSpec.describe BulkUpload::Sales::Year2022::CsvParser do
let(:log) { build(:sales_log, :completed) }
before do
file.write(BulkUpload::LogToCsv.new(log:, col_offset: 0).to_2022_sales_csv_row)
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_2022_csv_row)
file.rewind
end

153
spec/support/bulk_upload/log_to_csv.rb → spec/support/bulk_upload/lettings_log_to_csv.rb

@ -1,4 +1,4 @@
class BulkUpload::LogToCsv
class BulkUpload::LettingsLogToCsv
attr_reader :log, :line_ending, :col_offset, :overrides
def initialize(log:, line_ending: "\n", col_offset: 1, overrides: {})
@ -21,10 +21,6 @@ class BulkUpload::LogToCsv
end
end
def to_2022_sales_csv_row
(row_prefix + to_2022_sales_row).flatten.join(",") + line_ending
end
def default_2022_field_numbers
(1..134).to_a
end
@ -234,153 +230,6 @@ class BulkUpload::LogToCsv
(row_prefix + row).flatten.join(",") + line_ending
end
def to_2022_sales_row
[
log.purchid, # 1
log.saledate&.day,
log.saledate&.month,
log.saledate&.strftime("%y"),
nil,
log.noint,
log.age1,
log.age2,
log.age3,
log.age4,
log.age5,
log.age6,
log.sex1,
log.sex2,
log.sex3,
log.sex4,
log.sex5,
log.sex6,
log.relat2,
log.relat3, # 20
log.relat4,
log.relat5,
log.relat6,
log.ecstat1,
log.ecstat2,
log.ecstat3,
log.ecstat4,
log.ecstat5,
log.ecstat6,
log.ethnic, # 30
log.national,
log.income1,
log.income2,
log.inc1mort,
log.inc2mort,
log.savings,
log.prevown,
nil,
log.prevten,
log.prevloc, # 40
((log.ppostcode_full || "").split(" ") || [""]).first,
((log.ppostcode_full || "").split(" ") || [""]).last,
log.ppcodenk == 0 ? 1 : nil,
log.pregyrha,
log.pregla,
log.pregghb,
log.pregother,
log.disabled,
log.wheel,
log.beds, # 50
log.proptype,
log.builtype,
log.la,
((log.postcode_full || "").split(" ") || [""]).first,
((log.postcode_full || "").split(" ") || [""]).last,
log.wchair,
log.type, # shared ownership
log.resale,
log.hodate&.day,
log.hodate&.month, # 60
log.hodate&.strftime("%y"),
log.exdate&.day,
log.exdate&.month,
log.exdate&.strftime("%y"),
log.lanomagr,
log.frombeds,
log.fromprop,
log.value,
log.equity,
log.mortgage, # 70
log.extrabor,
log.deposit,
log.cashdis,
log.mrent,
log.mscharge,
log.type, # discounted ownership
log.value,
log.grant,
log.discount,
log.mortgage, # 80
log.extrabor,
log.deposit,
log.mscharge,
log.type, # outright sale
log.othtype,
nil,
log.value,
log.mortgage,
log.extrabor,
log.deposit, # 90
log.mscharge,
overrides[:organisation_id] || log.owning_organisation&.old_visible_id,
log.created_by&.email,
nil,
hhregres,
nil,
log.armedforcesspouse,
log.mortgagelender, # shared ownership
log.mortgagelenderother,
log.mortgagelender, # discounted ownership 100
log.mortgagelenderother,
log.mortgagelender, # outright ownership
log.mortgagelenderother,
log.hb,
log.mortlen, # shared ownership
log.mortlen, # discounted ownership
log.mortlen, # outright ownership
log.proplen, # discounted ownership
log.jointmore,
log.proplen, # shared ownership 110
log.staircase,
log.privacynotice,
log.ownershipsch,
log.companybuy, # outright sale
log.buylivein,
log.jointpur,
log.buy1livein,
log.buy2livein,
log.hholdcount,
log.stairbought, # 120
log.stairowned,
log.socprevten,
log.mortgageused, # shared ownership
log.mortgageused, # discounted ownership
log.mortgageused, # outright ownership
]
end
private
def renewal

187
spec/support/bulk_upload/sales_log_to_csv.rb

@ -0,0 +1,187 @@
class BulkUpload::SalesLogToCsv
attr_reader :log, :line_ending, :col_offset, :overrides
def initialize(log:, line_ending: "\n", col_offset: 1, overrides: {})
@log = log
@line_ending = line_ending
@col_offset = col_offset
@overrides = overrides
end
def row_prefix
[nil] * col_offset
end
def to_2022_csv_row
(row_prefix + to_2022_row).flatten.join(",") + line_ending
end
def default_2022_field_numbers
(1..125).to_a
end
def default_2022_field_numbers_row(seed: nil)
if seed
["Bulk upload field number"] + default_2022_field_numbers.shuffle(random: Random.new(seed))
else
["Bulk upload field number"] + default_2022_field_numbers
end.flatten.join(",") + line_ending
end
def to_2022_row
[
log.purchid, # 1
log.saledate&.day,
log.saledate&.month,
log.saledate&.strftime("%y"),
nil,
log.noint,
log.age1,
log.age2,
log.age3,
log.age4,
log.age5,
log.age6,
log.sex1,
log.sex2,
log.sex3,
log.sex4,
log.sex5,
log.sex6,
log.relat2,
log.relat3, # 20
log.relat4,
log.relat5,
log.relat6,
log.ecstat1,
log.ecstat2,
log.ecstat3,
log.ecstat4,
log.ecstat5,
log.ecstat6,
log.ethnic, # 30
log.national,
log.income1,
log.income2,
log.inc1mort,
log.inc2mort,
log.savings,
log.prevown,
nil,
log.prevten,
log.prevloc, # 40
((log.ppostcode_full || "").split(" ") || [""]).first,
((log.ppostcode_full || "").split(" ") || [""]).last,
log.ppcodenk == 0 ? 1 : nil,
log.pregyrha,
log.pregla,
log.pregghb,
log.pregother,
log.disabled,
log.wheel,
log.beds, # 50
log.proptype,
log.builtype,
log.la,
((log.postcode_full || "").split(" ") || [""]).first,
((log.postcode_full || "").split(" ") || [""]).last,
log.wchair,
log.type, # shared ownership
log.resale,
log.hodate&.day,
log.hodate&.month, # 60
log.hodate&.strftime("%y"),
log.exdate&.day,
log.exdate&.month,
log.exdate&.strftime("%y"),
log.lanomagr,
log.frombeds,
log.fromprop,
log.value,
log.equity,
log.mortgage, # 70
log.extrabor,
log.deposit,
log.cashdis,
log.mrent,
log.mscharge,
log.type, # discounted ownership
log.value,
log.grant,
log.discount,
log.mortgage, # 80
log.extrabor,
log.deposit,
log.mscharge,
log.type, # outright sale
log.othtype,
nil,
log.value,
log.mortgage,
log.extrabor,
log.deposit, # 90
log.mscharge,
overrides[:organisation_id] || log.owning_organisation&.old_visible_id,
log.created_by&.email,
nil,
hhregres,
nil,
log.armedforcesspouse,
log.mortgagelender, # shared ownership
log.mortgagelenderother,
log.mortgagelender, # discounted ownership 100
log.mortgagelenderother,
log.mortgagelender, # outright ownership
log.mortgagelenderother,
log.hb,
log.mortlen, # shared ownership
log.mortlen, # discounted ownership
log.mortlen, # outright ownership
log.proplen, # discounted ownership
log.jointmore,
log.proplen, # shared ownership 110
log.staircase,
log.privacynotice,
log.ownershipsch,
log.companybuy, # outright sale
log.buylivein,
log.jointpur,
log.buy1livein,
log.buy2livein,
log.hholdcount,
log.stairbought, # 120
log.stairowned,
log.socprevten,
log.mortgageused, # shared ownership
log.mortgageused, # discounted ownership
log.mortgageused, # outright ownership
]
end
private
def hhregres
if log.hhregres == 1
log.hhregresstill
else
log.hhregres
end
end
end
Loading…
Cancel
Save