From 9881fb990aa374fd9d80ff750b2fb17f6308acb1 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:18:02 +0000 Subject: [PATCH] CLDC-3339 Improve select correct address bulk upload error (#2331) * feat: add unable to find address errors when some options are returned if they are low confidence * feat: update copy * feat: add tests --- .../bulk_upload/lettings/year2024/row_parser.rb | 2 +- .../bulk_upload/sales/year2024/row_parser.rb | 2 +- config/locales/en.yml | 2 +- .../lettings/year2024/row_parser_spec.rb | 17 +++++++++++++++++ .../sales/year2024/row_parser_spec.rb | 17 +++++++++++++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index b0802df12..0ad096c2a 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -574,7 +574,7 @@ private end def validate_address_option_found - if !log.address_options_present? && field_16.blank? && (field_17.present? || field_19.present?) + if log.uprn_selection.nil? && field_16.blank? && (field_17.present? || field_19.present?) %i[field_17 field_18 field_19 field_20 field_21 field_22].each do |field| errors.add(field, I18n.t("validations.no_address_found")) end diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index be6a9ca63..e5f4f1d61 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -602,7 +602,7 @@ private end def validate_address_option_found - if !log.address_options_present? && field_22.blank? && (field_23.present? || field_25.present?) + if log.uprn_selection.nil? && field_22.blank? && (field_23.present? || field_25.present?) %i[field_23 field_24 field_25 field_26 field_27 field_28].each do |field| errors.add(field, I18n.t("validations.no_address_found")) end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2f3e63020..e2934273f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -213,7 +213,7 @@ en: not_answered: "You must answer %{question}" invalid_option: "Enter a valid value for %{question}" invalid_number: "Enter a number for %{question}" - no_address_found: "We could not find this address. Edit the address data or fix this error on the CORE site." + no_address_found: "We could not find this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site." other_field_missing: "If %{main_field_label} is other then %{other_field_label} must be provided" other_field_not_required: "%{other_field_label} must not be provided if %{main_field_label} was not other" diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index 939d90297..c19dbcbc0 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -1521,6 +1521,23 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end + describe "address fields" do + context "when no address can be found" do + before do + stub_request(:get, /api\.os\.uk\/search\/places\/v1\/find/) + .to_return(status: 200, body: nil, headers: {}) + end + + let(:attributes) { setup_section_params.merge({ field_16: nil, field_17: "address line 1", field_19: "town or city" }) } + + it "adds an appropriate error" do + %i[field_17 field_18 field_19 field_20 field_21 field_22].each do |field| + expect(parser.errors[field]).to eql(["We could not find this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site."]) + end + end + end + end + describe "#field_25" do # unitletas context "when no longer a valid option from previous year" do let(:attributes) { setup_section_params.merge({ field_25: "4" }) } 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 e68e95f06..d80aca533 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -886,6 +886,23 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end + describe "address fields" do + context "when no address can be found" do + before do + stub_request(:get, /api\.os\.uk\/search\/places\/v1\/find/) + .to_return(status: 200, body: nil, headers: {}) + end + + let(:attributes) { setup_section_params.merge({ field_22: nil, field_23: "address line 1", field_25: "town or city" }) } + + it "adds an appropriate error" do + %i[field_23 field_24 field_25 field_26 field_27 field_28].each do |field| + expect(parser.errors[field]).to eql(["We could not find this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site."]) + end + end + end + end + describe "#field_18" do # data protection let(:attributes) { setup_section_params.merge({ field_18: nil }) }