diff --git a/app/services/bulk_upload/lettings/year2024/row_parser.rb b/app/services/bulk_upload/lettings/year2024/row_parser.rb index 3d34d6305..3f5227c44 100644 --- a/app/services/bulk_upload/lettings/year2024/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2024/row_parser.rb @@ -617,7 +617,9 @@ private def validate_address_option_found if log.uprn.nil? && field_16.blank? && key_address_fields_provided? error_message = if log.address_options_present? && log.address_options.size > 1 - I18n.t("#{ERROR_BASE_KEY}.address.not_determined") + 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 b28581edb..443d5e665 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -615,7 +615,9 @@ private def validate_address_option_found if log.uprn.nil? && field_22.blank? && key_address_fields_provided? error_message = if log.address_options_present? && log.address_options.size > 1 - I18n.t("#{ERROR_BASE_KEY}.address.not_determined") + 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 892cd6f88..a22f65fa5 100644 --- a/config/locales/validations/lettings/2024/bulk_upload.en.yml +++ b/config/locales/validations/lettings/2024/bulk_upload.en.yml @@ -49,8 +49,10 @@ 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 find the correct address using the CORE site." - not_determined: "There are multiple matches for this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site." + 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/config/locales/validations/sales/2024/bulk_upload.en.yml b/config/locales/validations/sales/2024/bulk_upload.en.yml index 860eae137..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 find the correct address using the CORE site." - not_determined: "There are multiple matches for this address. Check the address data in your CSV file is correct and complete, or select the correct address using the CORE site." + 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..14a1d9326 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,31 @@ 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 f3f7da486..0c38034db 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -1104,7 +1104,7 @@ 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_found")]) + expect(parser.errors[field]).to eql([I18n.t("validations.sales.2024.bulk_upload.address.not_determined.one")]) end end end @@ -1128,7 +1128,7 @@ 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.multiple")]) end end end