From e5a75d62a4a3b348ff23ea14714478805073298b Mon Sep 17 00:00:00 2001 From: oscric Date: Tue, 11 Aug 2026 11:12:28 +0100 Subject: [PATCH] Add supported housing only error message to Q16 --- app/controllers/form_controller.rb | 2 +- .../form/lettings/questions/address_search.rb | 6 ++ .../form/lettings/questions/declaration.rb | 2 +- app/models/form/lettings/questions/uprn.rb | 2 +- .../form/lettings/questions/uprn_known.rb | 2 +- app/models/form/question.rb | 2 +- .../form/sales/questions/privacy_notice.rb | 2 +- app/models/form/sales/questions/uprn.rb | 2 +- app/models/form/sales/questions/uprn_known.rb | 2 +- .../lettings/property_information.en.yml | 2 + .../pages/property_local_authority_spec.rb | 66 +++++++++++++------ .../lettings/questions/address_search_spec.rb | 30 +++++++++ 12 files changed, 93 insertions(+), 27 deletions(-) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 6dba53a8a..469151236 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -35,7 +35,7 @@ class FormController < ApplicationController else @log.valid? if mandatory_questions_with_no_response.any? mandatory_questions_with_no_response.map do |question| - @log.errors.add question.id.to_sym, question.unanswered_error_message, category: :not_answered + @log.errors.add question.id.to_sym, question.unanswered_error_message(@log), category: :not_answered end error_attributes = @log.errors.map(&:attribute) Rails.logger.info "User triggered validation(s) on: #{error_attributes.join(', ')}" diff --git a/app/models/form/lettings/questions/address_search.rb b/app/models/form/lettings/questions/address_search.rb index eb970a5e5..8d9370c22 100644 --- a/app/models/form/lettings/questions/address_search.rb +++ b/app/models/form/lettings/questions/address_search.rb @@ -10,6 +10,12 @@ class Form::Lettings::Questions::AddressSearch < ::Form::Question @hide_question_number_on_page = true end + def unanswered_error_message(log = nil) + return super unless log&.is_supported_housing? + + I18n.t("validations.lettings.property.address.not_answered_supported_housing") + end + def answer_options(log = nil, _user = nil) return {} unless ActiveRecord::Base.connected? return {} unless log&.address_search_options&.any? diff --git a/app/models/form/lettings/questions/declaration.rb b/app/models/form/lettings/questions/declaration.rb index 6a2572487..7c5c7ebdb 100644 --- a/app/models/form/lettings/questions/declaration.rb +++ b/app/models/form/lettings/questions/declaration.rb @@ -18,7 +18,7 @@ class Form::Lettings::Questions::Declaration < ::Form::Question { "declaration" => { "value" => declaration_text } }.freeze end - def unanswered_error_message + def unanswered_error_message(_log = nil) if form.start_year_2024_or_later? I18n.t("validations.declaration.missing.post_2024") else diff --git a/app/models/form/lettings/questions/uprn.rb b/app/models/form/lettings/questions/uprn.rb index 98ffb75c2..f95a02f7e 100644 --- a/app/models/form/lettings/questions/uprn.rb +++ b/app/models/form/lettings/questions/uprn.rb @@ -14,7 +14,7 @@ class Form::Lettings::Questions::Uprn < ::Form::Question ] end - def unanswered_error_message + def unanswered_error_message(_log = nil) I18n.t("validations.lettings.property.uprn.invalid") end diff --git a/app/models/form/lettings/questions/uprn_known.rb b/app/models/form/lettings/questions/uprn_known.rb index 5dab0f35a..dfc79d3ae 100644 --- a/app/models/form/lettings/questions/uprn_known.rb +++ b/app/models/form/lettings/questions/uprn_known.rb @@ -26,7 +26,7 @@ class Form::Lettings::Questions::UprnKnown < ::Form::Question "0" => { "value" => "No" }, }.freeze - def unanswered_error_message + def unanswered_error_message(_log = nil) I18n.t("validations.property.uprn_known.invalid") end diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 9b38cf511..edbbaf3f3 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -240,7 +240,7 @@ class Form::Question format_ending(label) end - def unanswered_error_message + def unanswered_error_message(_log = nil) question_text = error_display_label.presence || "this question." I18n.t("validations.not_answered", question: question_text.downcase) end diff --git a/app/models/form/sales/questions/privacy_notice.rb b/app/models/form/sales/questions/privacy_notice.rb index aac52baca..be949f7d3 100644 --- a/app/models/form/sales/questions/privacy_notice.rb +++ b/app/models/form/sales/questions/privacy_notice.rb @@ -19,7 +19,7 @@ class Form::Sales::Questions::PrivacyNotice < ::Form::Question { "privacynotice" => { "value" => declaration_text } }.freeze end - def unanswered_error_message + def unanswered_error_message(_log = nil) buyer_or_buyers = @joint_purchase ? "buyers" : "buyer" if form.start_year_2024_or_later? I18n.t("validations.privacynotice.missing.post_2024", buyer_or_buyers:) diff --git a/app/models/form/sales/questions/uprn.rb b/app/models/form/sales/questions/uprn.rb index 841818d58..f6e1b2ae2 100644 --- a/app/models/form/sales/questions/uprn.rb +++ b/app/models/form/sales/questions/uprn.rb @@ -14,7 +14,7 @@ class Form::Sales::Questions::Uprn < ::Form::Question ] end - def unanswered_error_message + def unanswered_error_message(_log = nil) I18n.t("validations.sales.property_information.uprn.invalid") end diff --git a/app/models/form/sales/questions/uprn_known.rb b/app/models/form/sales/questions/uprn_known.rb index af84c09f9..57a6d9c3c 100644 --- a/app/models/form/sales/questions/uprn_known.rb +++ b/app/models/form/sales/questions/uprn_known.rb @@ -26,7 +26,7 @@ class Form::Sales::Questions::UprnKnown < ::Form::Question "0" => { "value" => "No" }, }.freeze - def unanswered_error_message + def unanswered_error_message(_log = nil) I18n.t("validations.sales.property_information.uprn_known.invalid") end diff --git a/config/locales/validations/lettings/property_information.en.yml b/config/locales/validations/lettings/property_information.en.yml index 15ea86f0e..e40b92f64 100644 --- a/config/locales/validations/lettings/property_information.en.yml +++ b/config/locales/validations/lettings/property_information.en.yml @@ -2,6 +2,8 @@ en: validations: lettings: property: + address: + not_answered_supported_housing: "You must enter address. If your letting is in a confidential scheme, please check the scheme you chose in the ‘Set up this lettings log’ section. If a scheme needs updating to mark it as confidential, a CORE coordinator in your organisation can do this." postcode_full: invalid: "Enter a postcode in the correct format, for example AA1 1AA." not_in_england: "It looks like you have an entered a postcode outside of England. Only create logs for lettings in England." diff --git a/spec/models/form/lettings/pages/property_local_authority_spec.rb b/spec/models/form/lettings/pages/property_local_authority_spec.rb index 556f29a05..c2b09dab8 100644 --- a/spec/models/form/lettings/pages/property_local_authority_spec.rb +++ b/spec/models/form/lettings/pages/property_local_authority_spec.rb @@ -33,37 +33,65 @@ RSpec.describe Form::Lettings::Pages::PropertyLocalAuthority, type: :model do end context "when routing to the page" do - let(:log) { build(:lettings_log) } - before do allow(form).to receive(:start_year_2025_or_later?).and_return(true) end - it "is routed to when la is not inferred and it is general needs log" do - log.needstype = 1 - log.is_la_inferred = false - expect(page).to be_routed_to(log, nil) - end + context "when the log is general needs" do + let(:log) { build(:lettings_log, needstype: 1) } - it "is not routed to when la is inferred" do - log.needstype = 1 - log.is_la_inferred = true - expect(page).not_to be_routed_to(log, nil) - end + it "is not routed to when `is_la_inferred` is nil" do + log.is_la_inferred = nil + expect(page).not_to be_routed_to(log, nil) + end - it "is not routed to when it's a supported housing log" do - log.needstype = 2 - log.is_la_inferred = false - expect(page).not_to be_routed_to(log, nil) + it "is not routed to when LA is inferred" do + log.is_la_inferred = true + expect(page).not_to be_routed_to(log, nil) + end + + it "is routed to when LA is not inferred" do + log.is_la_inferred = false + expect(page).to be_routed_to(log, nil) + end end - context "when the scheme is confidential" do - let(:log) { build(:lettings_log, needstype: 2, scheme: build(:scheme, sensitive: 1)) } + context "when the log is supported housing" do + let(:log) { build(:lettings_log, needstype: 2) } - it "is not routed to, even when the LA could not be inferred" do + it "is not routed to when `is_la_inferred` is nil" do + log.is_la_inferred = nil + expect(page).not_to be_routed_to(log, nil) + end + + it "is not routed to when LA is inferred" do + log.is_la_inferred = true + expect(page).not_to be_routed_to(log, nil) + end + + it "is not routed to, even when LA is not inferred" do log.is_la_inferred = false expect(page).not_to be_routed_to(log, nil) end + + context "when the scheme has confidential information" do + let(:log) { build(:lettings_log, needstype: 2, scheme: build(:scheme, sensitive: 1)) } + + it "is not routed to when `is_la_inferred` is nil" do + log.is_la_inferred = nil + expect(page).not_to be_routed_to(log, nil) + end + + it "is not routed to when LA is inferred" do + log.is_la_inferred = true + expect(page).not_to be_routed_to(log, nil) + end + + it "is not routed to, even when LA is not inferred" do + log.is_la_inferred = false + expect(page).not_to be_routed_to(log, nil) + end + end end end end diff --git a/spec/models/form/lettings/questions/address_search_spec.rb b/spec/models/form/lettings/questions/address_search_spec.rb index 256531a65..c775839d5 100644 --- a/spec/models/form/lettings/questions/address_search_spec.rb +++ b/spec/models/form/lettings/questions/address_search_spec.rb @@ -65,6 +65,36 @@ RSpec.describe Form::Lettings::Questions::AddressSearch, type: :model do end end + describe "#unanswered_error_message" do + context "when the log is supported housing" do + let(:log) { build(:lettings_log, needstype: 2) } + + it "returns the confidential-scheme guidance message" do + expect(question.unanswered_error_message(log)).to eq( + "You must enter address. If your letting is in a confidential scheme, please check the scheme you chose in the ‘Set up this lettings log’ section. If a scheme needs updating to mark it as confidential, a CORE coordinator in your organisation can do this.", + ) + end + end + + context "when the log is general needs" do + let(:log) { build(:lettings_log, needstype: 1) } + + it "returns the default unanswered message" do + expect(question.unanswered_error_message(log)).to eq( + I18n.t("validations.not_answered", question: question.error_display_label.downcase), + ) + end + end + + context "when no log is given" do + it "returns the default unanswered message" do + expect(question.unanswered_error_message).to eq( + I18n.t("validations.not_answered", question: question.error_display_label.downcase), + ) + end + end + end + describe "get_extra_check_answer_value" do context "when address is not present" do let(:log) { build(:lettings_log, manual_address_entry_selected: false) }