From 455afced6e2c0300a9365f91ccacde68ac3f99d7 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Mon, 3 Feb 2025 19:06:48 +0000 Subject: [PATCH] Fix copy multiple matches for for this address (#2914) * Copy update * Update copy * Check address options returned is more than 1 * Update test * Update and add test * Update error messaging for single and multiple returns * lint * Fix lint --- .../lettings/year2024/row_parser.rb | 6 ++-- .../bulk_upload/sales/year2024/row_parser.rb | 6 ++-- .../lettings/2024/bulk_upload.en.yml | 10 ++++--- .../validations/sales/2024/bulk_upload.en.yml | 6 ++-- .../lettings/year2024/row_parser_spec.rb | 19 +++++++++++-- .../sales/year2024/row_parser_spec.rb | 28 +++++++++++++++++-- 6 files changed, 61 insertions(+), 14 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index 6315274ce..3f5227c44 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -616,8 +616,10 @@ private def validate_address_option_found if log.uprn.nil? && field_16.blank? && key_address_fields_provided? - error_message = if log.address_options_present? - I18n.t("#{ERROR_BASE_KEY}.address.not_determined") + error_message = if log.address_options_present? && log.address_options.size > 1 + I18n.t("#{ERROR_BASE_KEY}.address.not_determined.multiple") + elsif log.address_options_present? + I18n.t("#{ERROR_BASE_KEY}.address.not_determined.one") else I18n.t("#{ERROR_BASE_KEY}.address.not_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 0e7b72d6f..443d5e665 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -614,8 +614,10 @@ private def validate_address_option_found if log.uprn.nil? && field_22.blank? && key_address_fields_provided? - error_message = if log.address_options_present? - I18n.t("#{ERROR_BASE_KEY}.address.not_determined") + error_message = if log.address_options_present? && log.address_options.size > 1 + I18n.t("#{ERROR_BASE_KEY}.address.not_determined.multiple") + elsif log.address_options_present? + I18n.t("#{ERROR_BASE_KEY}.address.not_determined.one") else I18n.t("#{ERROR_BASE_KEY}.address.not_found") end diff --git a/config/locales/validations/lettings/2024/bulk_upload.en.yml b/config/locales/validations/lettings/2024/bulk_upload.en.yml index a16090543..a22f65fa5 100644 --- a/config/locales/validations/lettings/2024/bulk_upload.en.yml +++ b/config/locales/validations/lettings/2024/bulk_upload.en.yml @@ -17,7 +17,7 @@ en: owning_organisation: not_found: "The owning organisation code is incorrect." not_stock_owner: "The owning organisation code provided is for an organisation that does not own stock." - not_permitted: + not_permitted: not_support: "You do not have permission to add logs for this owning organisation." support: "This owning organisation is not affiliated with %{org_name}." managing_organisation: @@ -49,10 +49,12 @@ en: age: invalid: "Age of person %{person_num} must be a number or the letter R" address: - not_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." - not_determined: "There are multiple matches for this address. Either select the correct address manually or correct the UPRN in the CSV file." + not_found: "We could not find this address. Check the address data in your CSV file is correct and complete, or find the correct address in the service." + not_determined: + one: "There is a possible match for this address which doesn't look right. Check the address data in your CSV file is correct and complete, or confirm the address in the service." + multiple: "There are multiple matches for this address. Check the address data in your CSV file is correct and complete, or select the correct address in the service." not_answered: "Enter either the UPRN or the full address." nationality: invalid: "Select a valid nationality." charges: - missing_charges: "Please enter the %{sentence_fragment}. If there is no %{sentence_fragment}, please enter '0'." \ No newline at end of file + missing_charges: "Please enter the %{sentence_fragment}. If there is no %{sentence_fragment}, please enter '0'." diff --git a/config/locales/validations/sales/2024/bulk_upload.en.yml b/config/locales/validations/sales/2024/bulk_upload.en.yml index 4a2d88b46..31daa09f7 100644 --- a/config/locales/validations/sales/2024/bulk_upload.en.yml +++ b/config/locales/validations/sales/2024/bulk_upload.en.yml @@ -39,8 +39,10 @@ en: age2: buyer_cannot_be_over_16_and_child: "Buyer 2's age cannot be 16 or over if their working situation is child under 16." address: - not_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." - not_determined: "There are multiple matches for this address. Either select the correct address manually or correct the UPRN in the CSV file." + not_found: "We could not find this address. Check the address data in your CSV file is correct and complete, or find the correct address in the service." + not_determined: + one: "There is a possible match for this address which doesn't look right. Check the address data in your CSV file is correct and complete, or confirm the address in the service." + multiple: "There are multiple matches for this address. Check the address data in your CSV file is correct and complete, or select the correct address in the service." not_answered: "Enter either the UPRN or the full address." nationality: invalid: "Select a valid nationality." 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 01529a80b..b6ea44040 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -1710,7 +1710,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do end end - context "when no address has a high enough match rating" do + context "when a single address with not a high enough match rating is returned" do before do stub_request(:get, /api\.os\.uk\/search\/places\/v1\/find/) .to_return(status: 200, body: { results: [{ DPA: { MATCH: 0.6, BUILDING_NAME: "", POST_TOWN: "", POSTCODE: "AA1 1AA", UPRN: "1" } }] }.to_json, headers: {}) @@ -1720,7 +1720,22 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do parser.valid? expect(parser.errors[:field_16]).to be_empty %i[field_17 field_18 field_19 field_20 field_21 field_22].each do |field| - expect(parser.errors[field]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_determined")]) + expect(parser.errors[field]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_determined.one")]) + end + end + end + + context "when no addresses have a high enough match rating" do + before do + stub_request(:get, /api\.os\.uk\/search\/places\/v1\/find/) + .to_return(status: 200, body: { results: [{ DPA: { MATCH: 0.6, BUILDING_NAME: "", POST_TOWN: "", POSTCODE: "AA1 1AA", UPRN: "1" } }, { DPA: { MATCH: 0.8, BUILDING_NAME: "", POST_TOWN: "", POSTCODE: "BB2 2BB", UPRN: "2" } }] }.to_json, headers: {}) + end + + it "adds address not found errors to address fields only" do + parser.valid? + expect(parser.errors[:field_16]).to be_empty + %i[field_17 field_18 field_19 field_20 field_21 field_22].each do |field| + expect(parser.errors[field]).to eql([I18n.t("validations.lettings.2024.bulk_upload.address.not_determined.multiple")]) end end end 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 b449c57b0..efdb53bb9 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -1094,7 +1094,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end - context "when no address has a high enough match rating" do + context "when a single address with not a high enough match rating is returned" do before do stub_request(:get, /api\.os\.uk\/search\/places\/v1\/find/) .to_return(status: 200, body: { results: [{ DPA: { MATCH: 0.6, BUILDING_NAME: "", POST_TOWN: "", POSTCODE: "AA1 1AA", UPRN: "1" } }] }.to_json, headers: {}) @@ -1104,7 +1104,31 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do parser.valid? expect(parser.errors[:field_22]).to be_empty %i[field_23 field_24 field_25 field_26 field_27 field_28].each do |field| - expect(parser.errors[field]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_determined")]) + expect(parser.errors[field]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_determined.one")]) + end + end + end + + context "when no addresses have a high enough match rating" do + before do + stub_request(:get, /api\.os\.uk\/search\/places\/v1\/find/) + .to_return( + status: 200, + body: { + results: [ + { DPA: { MATCH: 0.6, BUILDING_NAME: "", POST_TOWN: "", POSTCODE: "AA1 1AA", UPRN: "1" } }, + { DPA: { MATCH: 0.8, BUILDING_NAME: "", POST_TOWN: "", POSTCODE: "BB2 2BB", UPRN: "2" } }, + ], + }.to_json, + headers: {}, + ) + end + + it "adds address not found errors to address fields only" do + parser.valid? + expect(parser.errors[:field_22]).to be_empty + %i[field_23 field_24 field_25 field_26 field_27 field_28].each do |field| + expect(parser.errors[field]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_determined.multiple")]) end end end