diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 57de4300e..93f15395f 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -243,13 +243,13 @@ class BulkUpload::Sales::Year2023::RowParser attribute :field_75, :integer attribute :field_76, :integer attribute :field_77, :integer - attribute :field_78, :integer + attribute :field_78, :string attribute :field_79, :integer - attribute :field_80, :integer + attribute :field_80, :string attribute :field_81, :integer attribute :field_82, :integer - attribute :field_83, :integer + attribute :field_83, :string attribute :field_84, :integer attribute :field_85, :integer attribute :field_86, :integer @@ -841,17 +841,17 @@ private attributes["ethnic"] = field_32 attributes["national"] = field_33 - attributes["income1nk"] = field_78.present? ? 0 : 1 - attributes["income1"] = field_78 + attributes["income1nk"] = field_78 == "R" ? 1 : 0 + attributes["income1"] = field_78.to_i if attributes["income1nk"]&.zero? && field_78&.match(/\A\d+\z/) - attributes["income2nk"] = field_80.present? ? 0 : 1 - attributes["income2"] = field_80 + attributes["income2nk"] = field_80 == "R" ? 1 : 0 + attributes["income2"] = field_80.to_i if attributes["income2nk"]&.zero? && field_80&.match(/\A\d+\z/) attributes["inc1mort"] = field_79 attributes["inc2mort"] = field_81 - attributes["savingsnk"] = field_83.present? ? 0 : 1 - attributes["savings"] = field_83 + attributes["savingsnk"] = field_83 == "R" ? 1 : 0 + attributes["savings"] = field_83.to_i if attributes["savingsnk"]&.zero? && field_83&.match(/\A\d+\z/) attributes["prevown"] = field_84 attributes["prevten"] = field_62 diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index 6f617b584..1056d4402 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -182,6 +182,54 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do end end + describe "income and savings fields" do + context "when set to R" do + let(:attributes) do + { + bulk_upload:, + field_78: "R", # income 1 + field_80: "R", # income 2 + field_83: "R", # savings + } + end + + it "sets the not known field as not known" do + expect(parser.log.income1nk).to be(1) + expect(parser.log.income2nk).to be(1) + expect(parser.log.savingsnk).to be(1) + end + + it "leaves the value field nil" do + expect(parser.log.income1).to be_nil + expect(parser.log.income2).to be_nil + expect(parser.log.savings).to be_nil + end + end + + context "when set to a number" do + let(:attributes) do + { + bulk_upload:, + field_78: "30000", # income 1 + field_80: "0", # income 2 + field_83: "12420", # savings + } + end + + it "sets the not known field as known" do + expect(parser.log.income1nk).to be(0) + expect(parser.log.income2nk).to be(0) + expect(parser.log.savingsnk).to be(0) + end + + it "sets the values" do + expect(parser.log.income1).to be(30_000) + expect(parser.log.income2).to be(0) + expect(parser.log.savings).to be(12_420) + end + end + end + describe "validations" do before do stub_request(:get, /api.postcodes.io/)