Browse Source

Add supported housing only error message to Q16

CLDC-4461-hide-confidential-addresses
oscric 1 day ago
parent
commit
e5a75d62a4
  1. 2
      app/controllers/form_controller.rb
  2. 6
      app/models/form/lettings/questions/address_search.rb
  3. 2
      app/models/form/lettings/questions/declaration.rb
  4. 2
      app/models/form/lettings/questions/uprn.rb
  5. 2
      app/models/form/lettings/questions/uprn_known.rb
  6. 2
      app/models/form/question.rb
  7. 2
      app/models/form/sales/questions/privacy_notice.rb
  8. 2
      app/models/form/sales/questions/uprn.rb
  9. 2
      app/models/form/sales/questions/uprn_known.rb
  10. 2
      config/locales/validations/lettings/property_information.en.yml
  11. 66
      spec/models/form/lettings/pages/property_local_authority_spec.rb
  12. 30
      spec/models/form/lettings/questions/address_search_spec.rb

2
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(', ')}"

6
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?

2
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

2
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

2
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

2
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

2
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:)

2
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

2
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

2
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."

66
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

30
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) }

Loading…
Cancel
Save