Browse Source

Fix null error setting and add builtype

pull/1148/head
Kat 3 years ago committed by Phil Lee
parent
commit
1e5859e496
  1. 7
      app/services/bulk_upload/lettings/row_parser.rb
  2. 31
      spec/services/bulk_upload/lettings/row_parser_spec.rb

7
app/services/bulk_upload/lettings/row_parser.rb

@ -196,8 +196,9 @@ private
end end
def validate_nulls def validate_nulls
field_mapping_for_errors.each do |question, fields| field_mapping_for_errors.each do |error_key, fields|
question = questions.find { |q| q.id == question } question_id = error_key.to_s
question = questions.find { |q| q.id == question_id }
next unless question next unless question
next if log.optional_fields.include?(question.id) next if log.optional_fields.include?(question.id)
@ -222,6 +223,7 @@ private
rent_type: %i[field_1 field_129 field_130], rent_type: %i[field_1 field_129 field_130],
startdate: %i[field_98 field_97 field_96], startdate: %i[field_98 field_97 field_96],
unittype_gn: %i[field_102], unittype_gn: %i[field_102],
builtype: %i[field_103],
} }
end end
@ -286,6 +288,7 @@ private
attributes["rent_type"] = rent_type attributes["rent_type"] = rent_type
attributes["startdate"] = startdate attributes["startdate"] = startdate
attributes["unittype_gn"] = field_102 attributes["unittype_gn"] = field_102
attributes["builtype"] = field_103
attributes attributes
end end

31
spec/services/bulk_upload/lettings/row_parser_spec.rb

@ -7,6 +7,18 @@ RSpec.describe BulkUpload::Lettings::RowParser do
let(:bulk_upload) { create(:bulk_upload, :lettings) } let(:bulk_upload) { create(:bulk_upload, :lettings) }
let(:owning_org) { create(:organisation) } let(:owning_org) { create(:organisation) }
let(:managing_org) { create(:organisation) } let(:managing_org) { create(:organisation) }
let(:setup_section_params) do
{
field_1: "1",
field_111: owning_org.old_visible_id,
field_113: managing_org.old_visible_id,
bulk_upload:,
field_96: "1",
field_97: "1",
field_98: "2023",
field_134: "0",
}
end
around do |example| around do |example|
FormHandler.instance.use_real_forms! FormHandler.instance.use_real_forms!
@ -50,6 +62,7 @@ RSpec.describe BulkUpload::Lettings::RowParser do
field_130: "1", field_130: "1",
field_134: "0", field_134: "0",
field_102: "2", field_102: "2",
field_103: "1",
} }
end end
@ -158,5 +171,23 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end end
end end
end end
describe "#field_103" do
context "when null" do
let(:attributes) { setup_section_params.merge({ field_103: nil }) }
it "returns an error" do
expect(parser.errors[:field_103]).to be_present
end
end
context "when unpermitted values" do
let(:attributes) { setup_section_params.merge({ field_103: "4" }) }
it "returns an error" do
expect(parser.errors[:field_103]).to be_present
end
end
end
end end
end end

Loading…
Cancel
Save