From e27b6fa9a050123568d4ebff29876016bc97a032 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 24 May 2023 16:43:01 +0100 Subject: [PATCH] Correctly set previous postcode known (#1658) --- .../bulk_upload/sales/year2022/row_parser.rb | 8 +++++- .../bulk_upload/sales/year2023/row_parser.rb | 8 +++++- .../sales/year2022/row_parser_spec.rb | 28 +++++++++++++++++++ .../sales/year2023/row_parser_spec.rb | 28 +++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index 7eafd7e06..8224e0d7a 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/app/services/bulk_upload/sales/year2022/row_parser.rb @@ -625,7 +625,7 @@ private attributes["prevten"] = buyer_not_interviewed? && field_39.blank? ? 0 : field_39 attributes["prevloc"] = field_40 attributes["previous_la_known"] = previous_la_known - attributes["ppcodenk"] = field_43 + attributes["ppcodenk"] = previous_postcode_known attributes["ppostcode_full"] = ppostcode_full attributes["pregyrha"] = field_44 @@ -907,6 +907,12 @@ private field_40.present? ? 1 : 0 end + def previous_postcode_known + return 1 if field_43.blank? + + 0 if field_43 == 1 + end + def soctenant return unless field_39 && field_113 diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index f2c3e6d8b..623a356d2 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -819,7 +819,7 @@ private attributes["prevten"] = field_62 attributes["prevloc"] = field_66 attributes["previous_la_known"] = previous_la_known - attributes["ppcodenk"] = field_63 + attributes["ppcodenk"] = previous_postcode_known attributes["ppostcode_full"] = ppostcode_full attributes["pregyrha"] = field_67 @@ -1107,6 +1107,12 @@ private field_66.present? ? 1 : 0 end + def previous_postcode_known + return 1 if field_63 == 2 + + 0 if field_63 == 1 + end + def block_log_creation! self.block_log_creation = true end 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 b3c008682..4a7b55300 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb @@ -144,6 +144,34 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do end end + describe "previous postcode known" do + context "when field_43 is 1" do + let(:attributes) do + { + bulk_upload:, + field_43: 1, + } + end + + it "sets previous postcode known to yes" do + expect(parser.log.ppcodenk).to eq(0) + end + end + + context "when field_43 is nil" do + let(:attributes) do + { + bulk_upload:, + field_43: nil, + } + end + + it "sets previous postcode known to no" do + expect(parser.log.ppcodenk).to eq(1) + end + end + end + describe "validations" do before do stub_request(:get, /api.postcodes.io/) 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 c63e83a12..e9a4e723e 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -147,6 +147,34 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do end end + describe "previous postcode known" do + context "when field_63 is 1" do + let(:attributes) do + { + bulk_upload:, + field_63: 1, + } + end + + it "sets previous postcode known to yes" do + expect(parser.log.ppcodenk).to eq(0) + end + end + + context "when field_63 is 2" do + let(:attributes) do + { + bulk_upload:, + field_63: 2, + } + end + + it "sets previous postcode known to no" do + expect(parser.log.ppcodenk).to eq(1) + end + end + end + describe "validations" do before do stub_request(:get, /api.postcodes.io/)