From 41bb0a743f83082b85977309d78c61a3193b5d67 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 20 Apr 2023 16:47:06 +0100 Subject: [PATCH] Fix details known and proplen mapping --- .../bulk_upload/sales/year2022/row_parser.rb | 18 ++-- .../sales/year2022/row_parser_spec.rb | 88 +++++++++++++++---- 2 files changed, 80 insertions(+), 26 deletions(-) diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index 7fefd85d9..cba51ba46 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/app/services/bulk_upload/sales/year2022/row_parser.rb @@ -327,9 +327,6 @@ private def field_mapping_for_errors { - age1_known: %i[field_7], - age1: %i[field_7], - buy1livein: %i[field_117], purchid: %i[field_1], saledate: %i[field_2 field_3 field_4], noint: %i[field_6], @@ -423,9 +420,8 @@ private mortgagelenderother: %i[field_99 field_101 field_103], hb: %i[field_104], mortlen: %i[field_105 field_106 field_107], - proplen: %i[field_108], + proplen: %i[field_108 field_110], jointmore: %i[field_109], - proplen: %i[field_110], staircase: %i[field_111], privacynotice: %i[field_112], ownershipsch: %i[field_113], @@ -570,9 +566,8 @@ private attributes["mortlen"] = mortlen - attributes["proplen"] = field_108 + attributes["proplen"] = proplen attributes["jointmore"] = field_109 - attributes["proplen"] = field_110 attributes["staircase"] = field_111 attributes["privacynotice"] = field_112 attributes["ownershipsch"] = field_113 @@ -653,7 +648,7 @@ private end def details_known?(person_n) - send("person_#{person_n}_present?") ? 0 : 1 + send("person_#{person_n}_present?") ? 1 : 2 end def ethnic_group_from_ethnic @@ -755,6 +750,13 @@ private end end + def proplen + case field_113 + when 1 then field_110 + when 2 then field_108 + end + end + def mortgageused case field_113 when 1 then field_123 diff --git a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb index 2678f87cb..12c3ea7d5 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/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_3: now.month.to_s, field_4: now.strftime("%g"), - field_134: "2", field_113: "1", field_57: "2", field_116: "2", @@ -115,22 +114,6 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do FormHandler.instance.use_fake_forms! 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 context "when a new object" do it "returns true" do @@ -177,7 +160,7 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do context "when valid row" do let(:attributes) { valid_attributes } - xit "returns true" do + it "returns true" do expect(parser).to be_valid end @@ -289,5 +272,74 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do 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