Browse Source

Fix details known and proplen mapping

pull/1574/head
Kat 3 years ago
parent
commit
41bb0a743f
  1. 18
      app/services/bulk_upload/sales/year2022/row_parser.rb
  2. 88
      spec/services/bulk_upload/sales/year2022/row_parser_spec.rb

18
app/services/bulk_upload/sales/year2022/row_parser.rb

@ -327,9 +327,6 @@ private
def field_mapping_for_errors def field_mapping_for_errors
{ {
age1_known: %i[field_7],
age1: %i[field_7],
buy1livein: %i[field_117],
purchid: %i[field_1], purchid: %i[field_1],
saledate: %i[field_2 field_3 field_4], saledate: %i[field_2 field_3 field_4],
noint: %i[field_6], noint: %i[field_6],
@ -423,9 +420,8 @@ private
mortgagelenderother: %i[field_99 field_101 field_103], mortgagelenderother: %i[field_99 field_101 field_103],
hb: %i[field_104], hb: %i[field_104],
mortlen: %i[field_105 field_106 field_107], mortlen: %i[field_105 field_106 field_107],
proplen: %i[field_108], proplen: %i[field_108 field_110],
jointmore: %i[field_109], jointmore: %i[field_109],
proplen: %i[field_110],
staircase: %i[field_111], staircase: %i[field_111],
privacynotice: %i[field_112], privacynotice: %i[field_112],
ownershipsch: %i[field_113], ownershipsch: %i[field_113],
@ -570,9 +566,8 @@ private
attributes["mortlen"] = mortlen attributes["mortlen"] = mortlen
attributes["proplen"] = field_108 attributes["proplen"] = proplen
attributes["jointmore"] = field_109 attributes["jointmore"] = field_109
attributes["proplen"] = field_110
attributes["staircase"] = field_111 attributes["staircase"] = field_111
attributes["privacynotice"] = field_112 attributes["privacynotice"] = field_112
attributes["ownershipsch"] = field_113 attributes["ownershipsch"] = field_113
@ -653,7 +648,7 @@ private
end end
def details_known?(person_n) def details_known?(person_n)
send("person_#{person_n}_present?") ? 0 : 1 send("person_#{person_n}_present?") ? 1 : 2
end end
def ethnic_group_from_ethnic def ethnic_group_from_ethnic
@ -755,6 +750,13 @@ private
end end
end end
def proplen
case field_113
when 1 then field_110
when 2 then field_108
end
end
def mortgageused def mortgageused
case field_113 case field_113
when 1 then field_123 when 1 then field_123

88
spec/services/bulk_upload/sales/year2022/row_parser_spec.rb

@ -19,7 +19,6 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
field_2: now.day.to_s, field_2: now.day.to_s,
field_3: now.month.to_s, field_3: now.month.to_s,
field_4: now.strftime("%g"), field_4: now.strftime("%g"),
field_134: "2",
field_113: "1", field_113: "1",
field_57: "2", field_57: "2",
field_116: "2", field_116: "2",
@ -115,22 +114,6 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
FormHandler.instance.use_fake_forms! FormHandler.instance.use_fake_forms!
end end
describe "validations" do
before do
parser.valid?
end
xdescribe "#field_117" do
context "when not a possible value" do
let(:attributes) { { bulk_upload:, field_117: "3" } }
it "is not valid" do
expect(parser.errors).to include(:field_117)
end
end
end
end
describe "#blank_row?" do describe "#blank_row?" do
context "when a new object" do context "when a new object" do
it "returns true" do it "returns true" do
@ -177,7 +160,7 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
context "when valid row" do context "when valid row" do
let(:attributes) { valid_attributes } let(:attributes) { valid_attributes }
xit "returns true" do it "returns true" do
expect(parser).to be_valid expect(parser).to be_valid
end end
@ -289,5 +272,74 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
end end
end end
end end
[
%w[age1_known age1 field_7],
%w[age2_known age2 field_8],
%w[age3_known age3 field_9],
%w[age4_known age4 field_10],
%w[age5_known age5 field_11],
%w[age6_known age6 field_12],
].each do |known, age, field|
describe "##{known} and ##{age}" do
context "when #{field} is blank" do
let(:attributes) { { bulk_upload:, field.to_s => nil } }
it "sets ##{known} 1" do
expect(parser.log.public_send(known)).to be(1)
end
it "sets ##{age} to nil" do
expect(parser.log.public_send(age)).to be_nil
end
end
context "when #{field} is R" do
let(:attributes) { setup_section_params.merge({ field.to_s => "R", field_6: "1", field_119: "5", field_112: "1" }) }
it "sets ##{known} 1" do
expect(parser.log.public_send(known)).to be(1)
end
it "sets ##{age} to nil" do
expect(parser.log.public_send(age)).to be_nil
end
end
context "when #{field} is a number" do
let(:attributes) { setup_section_params.merge({ field.to_s => "50", field_6: "1", field_119: "5", field_112: "1" }) }
it "sets ##{known} to 0" do
expect(parser.log.public_send(known)).to be(0)
end
it "sets ##{age} to given age" do
expect(parser.log.public_send(age)).to be(50)
end
end
context "when #{field} is a non-sensical value" do
let(:attributes) { setup_section_params.merge({ field.to_s => "A", field_6: "1", field_119: "5", field_112: "1" }) }
it "sets ##{known} to 0" do
expect(parser.log.public_send(known)).to be(0)
end
it "sets ##{age} to nil" do
expect(parser.log.public_send(age)).to be_nil
end
end
end
end
xdescribe "#field_117" do
context "when not a possible value" do
let(:attributes) { { bulk_upload:, field_117: "3" } }
it "is not valid" do
expect(parser.errors).to include(:field_117)
end
end
end
end end
end end

Loading…
Cancel
Save