From 8ec211433bb572fb23a46573349cbc2082bc0cd1 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 25 Jan 2024 14:54:15 +0000 Subject: [PATCH] Rebase changes --- .../bulk_upload/sales/year2024/row_parser.rb | 18 +++---- .../sales/year2024/row_parser_spec.rb | 50 ++++++++++++++++++- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index f36c1be45..99d45aea2 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -238,13 +238,13 @@ class BulkUpload::Sales::Year2024::RowParser attribute :field_74, :integer attribute :field_75, :integer attribute :field_76, :integer - attribute :field_77, :integer + attribute :field_77, :string attribute :field_78, :integer - attribute :field_79, :integer + attribute :field_79, :string attribute :field_80, :integer attribute :field_81, :integer - attribute :field_82, :integer + attribute :field_82, :string attribute :field_83, :integer attribute :field_84, :integer attribute :field_85, :integer @@ -833,17 +833,17 @@ private attributes["ethnic"] = field_33 attributes["national"] = field_34 - attributes["income1nk"] = field_77.present? ? 0 : 1 - attributes["income1"] = field_77 + attributes["income1nk"] = field_77 == "R" ? 1 : 0 + attributes["income1"] = field_77.to_i if attributes["income1nk"]&.zero? && field_77&.match(/\A\d+\z/) - attributes["income2nk"] = field_79.present? ? 0 : 1 - attributes["income2"] = field_79 + attributes["income2nk"] = field_79 == "R" ? 1 : 0 + attributes["income2"] = field_79.to_i if attributes["income2nk"]&.zero? && field_79&.match(/\A\d+\z/) attributes["inc1mort"] = field_78 attributes["inc2mort"] = field_80 - attributes["savingsnk"] = field_82.present? ? 0 : 1 - attributes["savings"] = field_82 + attributes["savingsnk"] = field_82 == "R" ? 1 : 0 + attributes["savings"] = field_82.to_i if attributes["savingsnk"]&.zero? && field_82&.match(/\A\d+\z/) attributes["prevown"] = field_83 attributes["prevten"] = field_61 diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index e50c5a62b..9ecf31d21 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -185,9 +185,57 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end + describe "income and savings fields" do + context "when set to R" do + let(:attributes) do + { + bulk_upload:, + field_77: "R", # income 1 + field_79: "R", # income 2 + field_82: "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_77: "30000", # income 1 + field_79: "0", # income 2 + field_82: "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/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) parser.valid?