45 changed files with 210 additions and 11988 deletions
@ -1,43 +0,0 @@
|
||||
class Form::Sales::Pages::DiscountedSaleValueCheck < ::Form::Page |
||||
def initialize(id, hsh, subsection, person_index = nil) |
||||
super(id, hsh, subsection) |
||||
@depends_on = depends_on |
||||
@copy_key = "sales.soft_validations.discounted_sale_value_check" |
||||
@title_text = { |
||||
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "field_formatted_as_currency", |
||||
"arguments_for_key" => "value_with_discount", |
||||
"i18n_template" => "value_with_discount", |
||||
}, |
||||
], |
||||
} |
||||
@informative_text = { |
||||
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "field_formatted_as_currency", |
||||
"arguments_for_key" => "mortgage_deposit_and_grant_total", |
||||
"i18n_template" => "mortgage_deposit_and_grant_total", |
||||
}, |
||||
], |
||||
} |
||||
@person_index = person_index |
||||
@depends_on = [ |
||||
{ |
||||
"discounted_ownership_value_invalid?" => true, |
||||
}, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::DiscountedSaleValueCheck.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[value deposit ownershipsch mortgage mortgageused discount grant type] |
||||
end |
||||
end |
||||
@ -1,35 +0,0 @@
|
||||
class Form::Sales::Pages::ExtraBorrowingValueCheck < Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@depends_on = [ |
||||
{ |
||||
"extra_borrowing_expected_but_not_reported?" => true, |
||||
}, |
||||
] |
||||
@copy_key = "sales.soft_validations.extra_borrowing_value_check" |
||||
@title_text = { |
||||
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "field_formatted_as_currency", |
||||
"arguments_for_key" => "mortgage_and_deposit_total", |
||||
"i18n_template" => "mortgage_and_deposit_total", |
||||
}, |
||||
], |
||||
} |
||||
@informative_text = { |
||||
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.informative_text", |
||||
"arguments" => [], |
||||
} |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::ExtraBorrowingValueCheck.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[extrabor mortgage deposit value discount] |
||||
end |
||||
end |
||||
@ -1,35 +0,0 @@
|
||||
class Form::Sales::Pages::SharedOwnershipDepositValueCheck < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@depends_on = [ |
||||
{ |
||||
"shared_ownership_deposit_invalid?" => true, |
||||
}, |
||||
] |
||||
@copy_key = "sales.soft_validations.shared_ownership_deposit_value_check" |
||||
@title_text = { |
||||
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text", |
||||
"arguments" => [ |
||||
{ |
||||
"key" => "mortgage_deposit_and_discount_error_fields", |
||||
"i18n_template" => "mortgage_deposit_and_discount_error_fields", |
||||
}, |
||||
{ |
||||
"key" => "field_formatted_as_currency", |
||||
"arguments_for_key" => "mortgage_deposit_and_discount_total", |
||||
"i18n_template" => "mortgage_deposit_and_discount_total", |
||||
}, |
||||
], |
||||
} |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::SharedOwnershipDepositValueCheck.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[mortgage mortgageused cashdis type deposit value equity] |
||||
end |
||||
end |
||||
@ -1,22 +0,0 @@
|
||||
class Form::Sales::Questions::DiscountedSaleValueCheck < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "discounted_sale_value_check" |
||||
@copy_key = "sales.soft_validations.discounted_sale_value_check" |
||||
@type = "interruption_screen" |
||||
@answer_options = { |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
} |
||||
@hidden_in_check_answers = { |
||||
"depends_on" => [ |
||||
{ |
||||
"discounted_sale_value_check" => 0, |
||||
}, |
||||
{ |
||||
"discounted_sale_value_check" => 1, |
||||
}, |
||||
], |
||||
} |
||||
end |
||||
end |
||||
@ -1,22 +0,0 @@
|
||||
class Form::Sales::Questions::ExtraBorrowingValueCheck < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super(id, hsh, page) |
||||
@id = "extrabor_value_check" |
||||
@copy_key = "sales.soft_validations.extra_borrowing_value_check" |
||||
@type = "interruption_screen" |
||||
@answer_options = { |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
} |
||||
@hidden_in_check_answers = { |
||||
"depends_on" => [ |
||||
{ |
||||
"extrabor_value_check" => 0, |
||||
}, |
||||
{ |
||||
"extrabor_value_check" => 1, |
||||
}, |
||||
], |
||||
} |
||||
end |
||||
end |
||||
@ -1,22 +0,0 @@
|
||||
class Form::Sales::Questions::SharedOwnershipDepositValueCheck < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "shared_ownership_deposit_value_check" |
||||
@copy_key = "sales.soft_validations.shared_ownership_deposit_value_check" |
||||
@type = "interruption_screen" |
||||
@answer_options = { |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
} |
||||
@hidden_in_check_answers = { |
||||
"depends_on" => [ |
||||
{ |
||||
"shared_ownership_deposit_value_check" => 0, |
||||
}, |
||||
{ |
||||
"shared_ownership_deposit_value_check" => 1, |
||||
}, |
||||
], |
||||
} |
||||
end |
||||
end |
||||
@ -1,53 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::DiscountedSaleValueCheck, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection, index) } |
||||
|
||||
let(:page_id) { "discounted_sale_value_check" } |
||||
let(:page_definition) { nil } |
||||
let(:index) { 1 } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } |
||||
let(:subsection) { instance_double(Form::Subsection, form:) } |
||||
|
||||
it "has correct subsection" do |
||||
expect(page.subsection).to eq(subsection) |
||||
end |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[discounted_sale_value_check]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("discounted_sale_value_check") |
||||
end |
||||
|
||||
it "has the correct title_text" do |
||||
expect(page.title_text).to eq({ |
||||
"translation" => "forms.2024.sales.soft_validations.discounted_sale_value_check.title_text", |
||||
"arguments" => [{ "arguments_for_key" => "value_with_discount", "i18n_template" => "value_with_discount", "key" => "field_formatted_as_currency" }], |
||||
}) |
||||
end |
||||
|
||||
it "has the correct informative_text" do |
||||
expect(page.informative_text).to eq({ |
||||
"translation" => "forms.2024.sales.soft_validations.discounted_sale_value_check.informative_text", |
||||
"arguments" => [{ "arguments_for_key" => "mortgage_deposit_and_grant_total", "i18n_template" => "mortgage_deposit_and_grant_total", "key" => "field_formatted_as_currency" }], |
||||
}) |
||||
end |
||||
|
||||
it "is interruption screen page" do |
||||
expect(page.interruption_screen?).to be(true) |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([ |
||||
{ |
||||
"discounted_ownership_value_invalid?" => true, |
||||
}, |
||||
]) |
||||
end |
||||
|
||||
it "has correct interruption_screen_question_ids" do |
||||
expect(page.interruption_screen_question_ids).to eq(%w[value deposit ownershipsch mortgage mortgageused discount grant type]) |
||||
end |
||||
end |
||||
@ -1,44 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::SharedOwnershipDepositValueCheck, type: :model do |
||||
subject(:page) { described_class.new(page_id, page_definition, subsection) } |
||||
|
||||
let(:page_id) { "shared_ownership_deposit_value_check" } |
||||
let(:page_definition) { nil } |
||||
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } |
||||
let(:subsection) { instance_double(Form::Subsection, form:) } |
||||
|
||||
it "has correct subsection" do |
||||
expect(page.subsection).to eq(subsection) |
||||
end |
||||
|
||||
it "has correct questions" do |
||||
expect(page.questions.map(&:id)).to eq(%w[shared_ownership_deposit_value_check]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("shared_ownership_deposit_value_check") |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([ |
||||
{ |
||||
"shared_ownership_deposit_invalid?" => true, |
||||
}, |
||||
]) |
||||
end |
||||
|
||||
it "has the correct title_text" do |
||||
expect(page.title_text).to eq({ |
||||
"translation" => "forms.2024.sales.soft_validations.shared_ownership_deposit_value_check.title_text", |
||||
"arguments" => [ |
||||
{ "i18n_template" => "mortgage_deposit_and_discount_error_fields", "key" => "mortgage_deposit_and_discount_error_fields" }, |
||||
{ "arguments_for_key" => "mortgage_deposit_and_discount_total", "i18n_template" => "mortgage_deposit_and_discount_total", "key" => "field_formatted_as_currency" }, |
||||
], |
||||
}) |
||||
end |
||||
|
||||
it "has the correct interruption_screen_question_ids" do |
||||
expect(page.interruption_screen_question_ids).to eq(%w[mortgage mortgageused cashdis type deposit value equity]) |
||||
end |
||||
end |
||||
@ -1,45 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::DiscountedSaleValueCheck, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("discounted_sale_value_check") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("interruption_screen") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?(nil)).to be false |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
}) |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers" do |
||||
expect(question.hidden_in_check_answers).to eq({ |
||||
"depends_on" => [ |
||||
{ |
||||
"discounted_sale_value_check" => 0, |
||||
}, |
||||
{ |
||||
"discounted_sale_value_check" => 1, |
||||
}, |
||||
], |
||||
}) |
||||
end |
||||
end |
||||
@ -1,45 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::SharedOwnershipDepositValueCheck, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("shared_ownership_deposit_value_check") |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("interruption_screen") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?(nil)).to be false |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to eq({ |
||||
"0" => { "value" => "Yes" }, |
||||
"1" => { "value" => "No" }, |
||||
}) |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers" do |
||||
expect(question.hidden_in_check_answers).to eq({ |
||||
"depends_on" => [ |
||||
{ |
||||
"shared_ownership_deposit_value_check" => 0, |
||||
}, |
||||
{ |
||||
"shared_ownership_deposit_value_check" => 1, |
||||
}, |
||||
], |
||||
}) |
||||
end |
||||
end |
||||
@ -1,226 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe BulkUpload::Lettings::Year2023::CsvParser do |
||||
subject(:service) { described_class.new(path:) } |
||||
|
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:lettings_log, :completed) } |
||||
|
||||
context "when parsing csv with headers" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2023)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with headers with extra rows" do |
||||
before do |
||||
file.write("Section\n") |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2023)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(8) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with headers in arbitrary order" do |
||||
let(:seed) { rand } |
||||
|
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2023, seed:)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2023, seed:)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with extra invalid headers" do |
||||
let(:seed) { rand } |
||||
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] } |
||||
|
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
file.write("Can be empty?\n") |
||||
file.write("Type of letting the question applies to\n") |
||||
file.write("Duplicate check field?\n") |
||||
file.write(log_to_csv.custom_field_numbers_row(seed:, field_numbers:)) |
||||
file.write(log_to_csv.to_custom_csv_row(seed:, field_values:)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
|
||||
it "counts the number of valid field numbers correctly" do |
||||
expect(service).to be_correct_field_count |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv without headers" do |
||||
before do |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(0) |
||||
expect(service.col_offset).to eq(0) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing with BOM aka byte order mark" do |
||||
let(:bom) { "\uFEFF" } |
||||
|
||||
before do |
||||
file.write(bom) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when an invalid byte sequence" do |
||||
let(:invalid_sequence) { "\x81" } |
||||
|
||||
before do |
||||
file.write(invalid_sequence) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with carriage returns" do |
||||
before do |
||||
file.write("Question\r\n") |
||||
file.write("Additional info\r") |
||||
file.write("Values\r\n") |
||||
file.write("Can be empty?\r") |
||||
file.write("Type of letting the question applies to\r\n") |
||||
file.write("Duplicate check field?\r") |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2023)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
describe "#column_for_field", :aggregate_failures do |
||||
context "when with headers using default ordering" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2023)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_5")).to eql("B") |
||||
expect(service.column_for_field("field_22")).to eql("EL") |
||||
end |
||||
end |
||||
|
||||
context "when without headers using default ordering" do |
||||
before do |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_5")).to eql("A") |
||||
expect(service.column_for_field("field_22")).to eql("EK") |
||||
end |
||||
end |
||||
|
||||
context "when with headers using custom ordering" do |
||||
let(:seed) { 123 } |
||||
|
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2023, seed:)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2023, seed:)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_5")).to eql("N") |
||||
expect(service.column_for_field("field_22")).to eql("O") |
||||
expect(service.column_for_field("field_26")).to eql("B") |
||||
expect(service.column_for_field("field_25")).to eql("EF") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
File diff suppressed because it is too large
Load Diff
@ -1,254 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe BulkUpload::Lettings::Year2024::CsvParser do |
||||
subject(:service) { described_class.new(path:) } |
||||
|
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:lettings_log, :completed) } |
||||
|
||||
context "when parsing csv with headers" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when some csv headers are empty (and we don't care about them)" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
file.write("\n") |
||||
file.write("Type of letting the question applies to\n") |
||||
file.write("Duplicate check field?\n") |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with headers with extra rows" do |
||||
before do |
||||
file.write("Section\n") |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.write("\n") |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(8) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
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 |
||||
let(:seed) { rand } |
||||
|
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2024, seed:)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2024, seed:)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with extra invalid headers" do |
||||
let(:seed) { rand } |
||||
let(:log_to_csv) { BulkUpload::LettingsLogToCsv.new(log:) } |
||||
let(:field_numbers) { log_to_csv.default_2024_field_numbers + %w[invalid_field_number] } |
||||
let(:field_values) { log_to_csv.to_2024_row + %w[value_for_invalid_field_number] } |
||||
|
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
file.write("Can be empty?\n") |
||||
file.write("Type of letting the question applies to\n") |
||||
file.write("Duplicate check field?\n") |
||||
file.write(log_to_csv.custom_field_numbers_row(seed:, field_numbers:)) |
||||
file.write(log_to_csv.to_custom_csv_row(seed:, field_values:)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
|
||||
it "counts the number of valid field numbers correctly" do |
||||
expect(service).to be_correct_field_count |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv without headers" do |
||||
before do |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(0) |
||||
expect(service.col_offset).to eq(0) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing with BOM aka byte order mark" do |
||||
let(:bom) { "\uFEFF" } |
||||
|
||||
before do |
||||
file.write(bom) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when an invalid byte sequence" do |
||||
let(:invalid_sequence) { "\x81" } |
||||
|
||||
before do |
||||
file.write(invalid_sequence) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with carriage returns" do |
||||
before do |
||||
file.write("Question\r\n") |
||||
file.write("Additional info\r") |
||||
file.write("Values\r\n") |
||||
file.write("Can be empty?\r") |
||||
file.write("Type of letting the question applies to\r\n") |
||||
file.write("Duplicate check field?\r") |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_13).to eql(log.tenancycode) |
||||
end |
||||
end |
||||
|
||||
describe "#column_for_field", :aggregate_failures do |
||||
context "when with headers using default ordering" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_5")).to eql("F") |
||||
expect(service.column_for_field("field_22")).to eql("W") |
||||
end |
||||
end |
||||
|
||||
context "when without headers using default ordering" do |
||||
before do |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_5")).to eql("E") |
||||
expect(service.column_for_field("field_22")).to eql("V") |
||||
end |
||||
end |
||||
|
||||
context "when with headers using custom ordering" do |
||||
let(:seed) { 123 } |
||||
|
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::LettingsLogToCsv.new(log:).default_field_numbers_row_for_year(2024, seed:)) |
||||
file.write(BulkUpload::LettingsLogToCsv.new(log:).to_year_csv_row(2024, seed:)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_5")).to eql("B") |
||||
expect(service.column_for_field("field_22")).to eql("AS") |
||||
expect(service.column_for_field("field_26")).to eql("DH") |
||||
expect(service.column_for_field("field_25")).to eql("I") |
||||
end |
||||
end |
||||
end |
||||
end |
||||
File diff suppressed because it is too large
Load Diff
@ -1,170 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe BulkUpload::Sales::Year2023::CsvParser do |
||||
subject(:service) { described_class.new(path:) } |
||||
|
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
|
||||
context "when parsing csv with headers" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2023)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_19).to eql(log.uprn) |
||||
end |
||||
|
||||
it "counts the number of valid field numbers correctly" do |
||||
expect(service).to be_correct_field_count |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with headers in arbitrary order" do |
||||
let(:seed) { rand } |
||||
|
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2023, seed:)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2023, seed:)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_19).to eql(log.uprn) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv without headers" do |
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
|
||||
before do |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(0) |
||||
expect(service.col_offset).to eq(0) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_19).to eql(log.uprn) |
||||
end |
||||
end |
||||
|
||||
context "when parsing with BOM aka byte order mark" do |
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
let(:bom) { "\uFEFF" } |
||||
|
||||
before do |
||||
file.write(bom) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2023)) |
||||
file.close |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_19).to eql(log.uprn) |
||||
end |
||||
end |
||||
|
||||
context "when an invalid byte sequence" do |
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
let(:invalid_sequence) { "\x81" } |
||||
|
||||
before do |
||||
file.write(invalid_sequence) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2023)) |
||||
file.close |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_19).to eql(log.uprn) |
||||
end |
||||
end |
||||
|
||||
describe "#column_for_field", :aggregate_failures do |
||||
context "when headers present" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2023)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_1")).to eql("CO") |
||||
expect(service.column_for_field("field_99")).to eql("EK") |
||||
end |
||||
end |
||||
|
||||
context "when no headers" do |
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
|
||||
before do |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_1")).to eql("CN") |
||||
expect(service.column_for_field("field_99")).to eql("EJ") |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with carriage returns" do |
||||
before do |
||||
file.write("Question\r\n") |
||||
file.write("Additional info\r") |
||||
file.write("Values\r\n") |
||||
file.write("Can be empty?\r") |
||||
file.write("Type of letting the question applies to\r\n") |
||||
file.write("Duplicate check field?\r") |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2023)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2023)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_19).to eql(log.uprn) |
||||
end |
||||
end |
||||
end |
||||
File diff suppressed because it is too large
Load Diff
@ -1,191 +0,0 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe BulkUpload::Sales::Year2024::CsvParser do |
||||
subject(:service) { described_class.new(path:) } |
||||
|
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
|
||||
context "when parsing csv with headers" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.write("\n") |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_22).to eql(log.uprn) |
||||
end |
||||
|
||||
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 some csv headers are empty (and we don't care about them)" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
file.write("\n") |
||||
file.write("Type of letting the question applies to\n") |
||||
file.write("Duplicate check field?\n") |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.write("\n") |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_22).to eql(log.uprn) |
||||
end |
||||
|
||||
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 |
||||
let(:seed) { rand } |
||||
|
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2024, seed:)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2024, seed:)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(7) |
||||
expect(service.col_offset).to eq(1) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_22).to eql(log.uprn) |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv without headers" do |
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
|
||||
before do |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct offsets" do |
||||
expect(service.row_offset).to eq(0) |
||||
expect(service.col_offset).to eq(0) |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_22).to eql(log.uprn) |
||||
end |
||||
end |
||||
|
||||
context "when parsing with BOM aka byte order mark" do |
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
let(:bom) { "\uFEFF" } |
||||
|
||||
before do |
||||
file.write(bom) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2024)) |
||||
file.close |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_22).to eql(log.uprn) |
||||
end |
||||
end |
||||
|
||||
context "when an invalid byte sequence" do |
||||
let(:file) { Tempfile.new } |
||||
let(:path) { file.path } |
||||
let(:log) { build(:sales_log, :completed, :with_uprn) } |
||||
let(:invalid_sequence) { "\x81" } |
||||
|
||||
before do |
||||
file.write(invalid_sequence) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:, col_offset: 0).to_year_csv_row(2024)) |
||||
file.close |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_22).to eql(log.uprn) |
||||
end |
||||
end |
||||
|
||||
describe "#column_for_field", :aggregate_failures do |
||||
context "when headers present" do |
||||
before do |
||||
file.write("Question\n") |
||||
file.write("Additional info\n") |
||||
file.write("Values\n") |
||||
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::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "returns correct column" do |
||||
expect(service.column_for_field("field_1")).to eql("B") |
||||
expect(service.column_for_field("field_99")).to eql("CV") |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "when parsing csv with carriage returns" do |
||||
before do |
||||
file.write("Question\r\n") |
||||
file.write("Additional info\r") |
||||
file.write("Values\r\n") |
||||
file.write("Can be empty?\r") |
||||
file.write("Type of letting the question applies to\r\n") |
||||
file.write("Duplicate check field?\r") |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).default_field_numbers_row_for_year(2024)) |
||||
file.write(BulkUpload::SalesLogToCsv.new(log:).to_year_csv_row(2024)) |
||||
file.rewind |
||||
end |
||||
|
||||
it "parses csv correctly" do |
||||
expect(service.row_parsers[0].field_22).to eql(log.uprn) |
||||
end |
||||
end |
||||
end |
||||
Loading…
Reference in new issue