diff --git a/app/models/form/lettings/pages/referral_value_check.rb b/app/models/form/lettings/pages/referral_value_check.rb new file mode 100644 index 000000000..d98a17a5d --- /dev/null +++ b/app/models/form/lettings/pages/referral_value_check.rb @@ -0,0 +1,19 @@ +class Form::Lettings::Pages::ReferralValueCheck < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "referral_value_check" + @depends_on = [{ "la_referral_for_general_needs?" => true }] + @title_text = { + "translation" => "soft_validations.referral.title_text", + } + @informative_text = "" + end + + def questions + @questions ||= [Form::Lettings::Questions::ReferralValueCheck.new(nil, nil, self)] + end + + def interruption_screen_question_ids + %w[needstype referral] + end +end diff --git a/app/models/form/lettings/questions/referral_value_check.rb b/app/models/form/lettings/questions/referral_value_check.rb new file mode 100644 index 000000000..30aa45f4c --- /dev/null +++ b/app/models/form/lettings/questions/referral_value_check.rb @@ -0,0 +1,14 @@ +class Form::Lettings::Questions::ReferralValueCheck < ::Form::Question + def initialize(id, hsh, page) + super + @id = "referral_value_check" + @check_answer_label = "Referral confirmation" + @header = "Are you sure?" + @type = "interruption_screen" + @check_answers_card_number = 0 + @answer_options = ANSWER_OPTIONS + @hidden_in_check_answers = { "depends_on" => [{ "referral_value_check" => 0 }, { "referral_value_check" => 1 }] } + end + + ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze +end diff --git a/app/models/form/lettings/subsections/household_situation.rb b/app/models/form/lettings/subsections/household_situation.rb index e09033563..9db7c1f04 100644 --- a/app/models/form/lettings/subsections/household_situation.rb +++ b/app/models/form/lettings/subsections/household_situation.rb @@ -24,6 +24,7 @@ class Form::Lettings::Subsections::HouseholdSituation < ::Form::Subsection Form::Lettings::Pages::ReferralPrp.new(nil, nil, self), Form::Lettings::Pages::ReferralSupportedHousing.new(nil, nil, self), Form::Lettings::Pages::ReferralSupportedHousingPrp.new(nil, nil, self), + Form::Lettings::Pages::ReferralValueCheck.new(nil, nil, self), ].compact end end diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 6d15699cc..3d01c5284 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -568,6 +568,10 @@ class LettingsLog < Log end end + def la_referral_for_general_needs? + is_general_needs? && referral == 4 + end + private def reset_invalid_unresolved_log_fields! diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index acffc9cac..0a267b9e9 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -345,4 +345,34 @@ RSpec.describe Validations::SoftValidations do expect(record).to be_care_home_charge_expected_not_provided end end + + describe "#la_referral_for_general_needs?" do + it "returns false if needstype is 'Supported Housing'" do + record.needstype = 2 + record.referral = 4 + + expect(record).not_to be_la_referral_for_general_needs + end + + it "returns false if needstype is not given" do + record.needstype = nil + record.referral = 4 + + expect(record).not_to be_la_referral_for_general_needs + end + + it "returns false if referral is not given" do + record.needstype = 1 + record.referral = nil + + expect(record).not_to be_la_referral_for_general_needs + end + + it "returns true if needstype is 'General needs' and referral is 4" do + record.needstype = 1 + record.referral = 4 + + expect(record).to be_la_referral_for_general_needs + end + end end