From 3424cbc550ab9b82d98144a16bd9a688a13e6545 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Wed, 30 Oct 2024 11:45:26 +0000 Subject: [PATCH] CLDC-3366: Use single page for rent soft validation (#2724) * CLDC-3366: Use single page for rent soft validation * Fix tests --- .../lettings/pages/max_rent_value_check.rb | 24 ----------- .../lettings/pages/min_rent_value_check.rb | 24 ----------- .../form/lettings/pages/rent_value_check.rb | 35 ++++++++++++++++ .../questions/max_rent_value_check.rb | 15 ------- ...ent_value_check.rb => rent_value_check.rb} | 4 +- .../subsections/income_and_benefits.rb | 3 +- .../subsections/property_information.rb | 6 +-- app/models/validations/soft_validations.rb | 8 ++++ .../pages/max_rent_value_check_spec.rb | 33 --------------- .../pages/min_rent_value_check_spec.rb | 42 ------------------- .../questions/max_rent_value_check_spec.rb | 32 -------------- .../questions/min_rent_value_check_spec.rb | 32 -------------- .../subsections/income_and_benefits_spec.rb | 3 +- .../subsections/property_information_spec.rb | 42 ++----------------- spec/services/documentation_generator_spec.rb | 4 +- 15 files changed, 55 insertions(+), 252 deletions(-) delete mode 100644 app/models/form/lettings/pages/max_rent_value_check.rb delete mode 100644 app/models/form/lettings/pages/min_rent_value_check.rb create mode 100644 app/models/form/lettings/pages/rent_value_check.rb delete mode 100644 app/models/form/lettings/questions/max_rent_value_check.rb rename app/models/form/lettings/questions/{min_rent_value_check.rb => rent_value_check.rb} (77%) delete mode 100644 spec/models/form/lettings/pages/max_rent_value_check_spec.rb delete mode 100644 spec/models/form/lettings/pages/min_rent_value_check_spec.rb delete mode 100644 spec/models/form/lettings/questions/max_rent_value_check_spec.rb delete mode 100644 spec/models/form/lettings/questions/min_rent_value_check_spec.rb diff --git a/app/models/form/lettings/pages/max_rent_value_check.rb b/app/models/form/lettings/pages/max_rent_value_check.rb deleted file mode 100644 index f3280420b..000000000 --- a/app/models/form/lettings/pages/max_rent_value_check.rb +++ /dev/null @@ -1,24 +0,0 @@ -class Form::Lettings::Pages::MaxRentValueCheck < ::Form::Page - def initialize(id, hsh, subsection, check_answers_card_number: nil) - super(id, hsh, subsection) - @depends_on = [{ "rent_in_soft_max_range?" => true }] - @title_text = { - "translation" => "soft_validations.rent.outside_range_title", - "arguments" => [{ - "key" => "brent", - "label" => true, - "i18n_template" => "brent", - }], - } - @informative_text = I18n.t("soft_validations.rent.informative_text", higher_or_lower: "higher") - @check_answers_card_number = check_answers_card_number - end - - def questions - @questions ||= [Form::Lettings::Questions::MaxRentValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number)] - end - - def interruption_screen_question_ids - %w[brent period startdate uprn postcode_full la beds rent_type needstype] - end -end diff --git a/app/models/form/lettings/pages/min_rent_value_check.rb b/app/models/form/lettings/pages/min_rent_value_check.rb deleted file mode 100644 index ee26b4d7e..000000000 --- a/app/models/form/lettings/pages/min_rent_value_check.rb +++ /dev/null @@ -1,24 +0,0 @@ -class Form::Lettings::Pages::MinRentValueCheck < ::Form::Page - def initialize(id, hsh, subsection, check_answers_card_number: nil) - super(id, hsh, subsection) - @depends_on = [{ "rent_in_soft_min_range?" => true }] - @title_text = { - "translation" => "soft_validations.rent.outside_range_title", - "arguments" => [{ - "key" => "brent", - "label" => true, - "i18n_template" => "brent", - }], - } - @informative_text = I18n.t("soft_validations.rent.informative_text", higher_or_lower: "lower") - @check_answers_card_number = check_answers_card_number - end - - def questions - @questions ||= [Form::Lettings::Questions::MinRentValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number)] - end - - def interruption_screen_question_ids - %w[brent period startdate uprn postcode_full la beds rent_type needstype] - end -end diff --git a/app/models/form/lettings/pages/rent_value_check.rb b/app/models/form/lettings/pages/rent_value_check.rb new file mode 100644 index 000000000..a80dc7339 --- /dev/null +++ b/app/models/form/lettings/pages/rent_value_check.rb @@ -0,0 +1,35 @@ +class Form::Lettings::Pages::RentValueCheck < ::Form::Page + def initialize(id, hsh, subsection, check_answers_card_number: nil) + super(id, hsh, subsection) + @depends_on = [{ "rent_soft_validation_triggered?" => true }] + @title_text = { + "translation" => "soft_validations.rent.outside_range_title", + "arguments" => [ + { + "key" => "brent", + "label" => true, + "i18n_template" => "brent", + }, + ], + } + @informative_text = { + "translation" => "soft_validations.rent.informative_text", + "arguments" => [ + { + "key" => "rent_soft_validation_higher_or_lower_text", + "label" => false, + "i18n_template" => "higher_or_lower", + }, + ], + } + @check_answers_card_number = check_answers_card_number + end + + def questions + @questions ||= [Form::Lettings::Questions::RentValueCheck.new(nil, nil, self, check_answers_card_number: @check_answers_card_number)] + end + + def interruption_screen_question_ids + %w[brent period startdate uprn postcode_full la beds rent_type needstype] + end +end diff --git a/app/models/form/lettings/questions/max_rent_value_check.rb b/app/models/form/lettings/questions/max_rent_value_check.rb deleted file mode 100644 index 6936e9e36..000000000 --- a/app/models/form/lettings/questions/max_rent_value_check.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Form::Lettings::Questions::MaxRentValueCheck < ::Form::Question - def initialize(id, hsh, page, check_answers_card_number:) - super(id, hsh, page) - @id = "rent_value_check" - @check_answer_label = "Total rent confirmation" - @header = "Are you sure this is correct?" - @type = "interruption_screen" - @hint_text = I18n.t("soft_validations.rent.hint_text", higher_or_lower: "higher") - @check_answers_card_number = check_answers_card_number - @answer_options = ANSWER_OPTIONS - @hidden_in_check_answers = { "depends_on" => [{ "rent_value_check" => 0 }, { "rent_value_check" => 1 }] } - end - - ANSWER_OPTIONS = { "0" => { "value" => "Yes" }, "1" => { "value" => "No" } }.freeze -end diff --git a/app/models/form/lettings/questions/min_rent_value_check.rb b/app/models/form/lettings/questions/rent_value_check.rb similarity index 77% rename from app/models/form/lettings/questions/min_rent_value_check.rb rename to app/models/form/lettings/questions/rent_value_check.rb index ad4111c61..688499259 100644 --- a/app/models/form/lettings/questions/min_rent_value_check.rb +++ b/app/models/form/lettings/questions/rent_value_check.rb @@ -1,11 +1,11 @@ -class Form::Lettings::Questions::MinRentValueCheck < ::Form::Question +class Form::Lettings::Questions::RentValueCheck < ::Form::Question def initialize(id, hsh, page, check_answers_card_number:) super(id, hsh, page) @id = "rent_value_check" @check_answer_label = "Total rent confirmation" @header = "Are you sure this is correct?" @type = "interruption_screen" - @hint_text = I18n.t("soft_validations.rent.hint_text", higher_or_lower: "lower") + @hint_text = I18n.t("soft_validations.rent.hint_text") @check_answers_card_number = check_answers_card_number @answer_options = ANSWER_OPTIONS @hidden_in_check_answers = { "depends_on" => [{ "rent_value_check" => 0 }, { "rent_value_check" => 1 }] } diff --git a/app/models/form/lettings/subsections/income_and_benefits.rb b/app/models/form/lettings/subsections/income_and_benefits.rb index 1404ebf04..2be2fb9a5 100644 --- a/app/models/form/lettings/subsections/income_and_benefits.rb +++ b/app/models/form/lettings/subsections/income_and_benefits.rb @@ -24,8 +24,7 @@ class Form::Lettings::Subsections::IncomeAndBenefits < ::Form::Subsection Form::Lettings::Pages::RentBiWeekly.new(nil, nil, self), Form::Lettings::Pages::Rent4Weekly.new(nil, nil, self), Form::Lettings::Pages::RentMonthly.new(nil, nil, self), - Form::Lettings::Pages::MinRentValueCheck.new("brent_min_rent_value_check", nil, self, check_answers_card_number: 0), - Form::Lettings::Pages::MaxRentValueCheck.new("brent_max_rent_value_check", nil, self, check_answers_card_number: 0), + Form::Lettings::Pages::RentValueCheck.new("brent_rent_value_check", nil, self, check_answers_card_number: 0), Form::Lettings::Pages::SchargeValueCheck.new(nil, nil, self), Form::Lettings::Pages::PschargeValueCheck.new(nil, nil, self), Form::Lettings::Pages::SupchargValueCheck.new(nil, nil, self), diff --git a/app/models/form/lettings/subsections/property_information.rb b/app/models/form/lettings/subsections/property_information.rb index 67a22c7f5..3068faf92 100644 --- a/app/models/form/lettings/subsections/property_information.rb +++ b/app/models/form/lettings/subsections/property_information.rb @@ -10,8 +10,7 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection @pages ||= [ uprn_questions, Form::Lettings::Pages::PropertyLocalAuthority.new(nil, nil, self), - Form::Lettings::Pages::MinRentValueCheck.new("local_authority_min_rent_value_check", nil, self, check_answers_card_number: nil), - Form::Lettings::Pages::MaxRentValueCheck.new("local_authority_max_rent_value_check", nil, self, check_answers_card_number: nil), + Form::Lettings::Pages::RentValueCheck.new("local_authority_rent_value_check", nil, self, check_answers_card_number: nil), Form::Lettings::Pages::FirstTimePropertyLetAsSocialHousing.new(nil, nil, self), Form::Lettings::Pages::PropertyLetType.new(nil, nil, self), Form::Lettings::Pages::PropertyVacancyReasonNotFirstLet.new(nil, nil, self), @@ -21,8 +20,7 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection Form::Lettings::Pages::PropertyBuildingType.new(nil, nil, self), Form::Lettings::Pages::PropertyWheelchairAccessible.new(nil, nil, self), Form::Lettings::Pages::PropertyNumberOfBedrooms.new(nil, nil, self), - Form::Lettings::Pages::MinRentValueCheck.new("beds_min_rent_value_check", nil, self, check_answers_card_number: 0), - Form::Lettings::Pages::MaxRentValueCheck.new("beds_max_rent_value_check", nil, self, check_answers_card_number: 0), + Form::Lettings::Pages::RentValueCheck.new("beds_rent_value_check", nil, self, check_answers_card_number: 0), Form::Lettings::Pages::VoidDate.new(nil, nil, self), Form::Lettings::Pages::VoidDateValueCheck.new(nil, nil, self), Form::Lettings::Pages::PropertyMajorRepairs.new(nil, nil, self), diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 41309cef0..0b76f792b 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -27,6 +27,14 @@ module Validations::SoftValidations weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min) end + def rent_soft_validation_triggered? + rent_in_soft_min_range? || rent_in_soft_max_range? + end + + def rent_soft_validation_higher_or_lower_text + rent_in_soft_min_range? ? "lower" : "higher" + end + def rent_in_soft_min_range? return unless brent && weekly_value(brent) && startdate diff --git a/spec/models/form/lettings/pages/max_rent_value_check_spec.rb b/spec/models/form/lettings/pages/max_rent_value_check_spec.rb deleted file mode 100644 index 273272d8b..000000000 --- a/spec/models/form/lettings/pages/max_rent_value_check_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Lettings::Pages::MaxRentValueCheck, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } - - let(:page_id) { "max_rent_value_check" } - let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1))) } - - it "has correct subsection" do - expect(page.subsection).to eq(subsection) - end - - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[rent_value_check]) - end - - it "has the correct id" do - expect(page.id).to eq("max_rent_value_check") - end - - it "has correct depends_on" do - expect(page.depends_on).to eq([{ "rent_in_soft_max_range?" => true }]) - end - - it "has the correct title_text" do - expect(page.title_text).to eq({ "arguments" => [{ "i18n_template" => "brent", "key" => "brent", "label" => true }], "translation" => "soft_validations.rent.outside_range_title" }) - end - - it "has the correct interruption_screen_question_ids" do - expect(page.interruption_screen_question_ids).to eq(%w[brent period startdate uprn postcode_full la beds rent_type needstype]) - end -end diff --git a/spec/models/form/lettings/pages/min_rent_value_check_spec.rb b/spec/models/form/lettings/pages/min_rent_value_check_spec.rb deleted file mode 100644 index 950f2f43f..000000000 --- a/spec/models/form/lettings/pages/min_rent_value_check_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Lettings::Pages::MinRentValueCheck, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } - - let(:page_id) { "min_rent_value_check" } - let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1))) } - - it "has correct subsection" do - expect(page.subsection).to eq(subsection) - end - - it "has the correct description" do - expect(page.description).to be nil - end - - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[rent_value_check]) - end - - it "has the correct id" do - expect(page.id).to eq("min_rent_value_check") - end - - it "has correct depends_on" do - expect(page.depends_on).to eq( - [{ "rent_in_soft_min_range?" => true }], - ) - end - - it "has the correct title_text" do - expect(page.title_text).to eq({ - "translation" => "soft_validations.rent.outside_range_title", - "arguments" => [{ "i18n_template" => "brent", "key" => "brent", "label" => true }], - }) - end - - it "has the correct interruption_screen_question_ids" do - expect(page.interruption_screen_question_ids).to eq(%w[brent period startdate uprn postcode_full la beds rent_type needstype]) - end -end diff --git a/spec/models/form/lettings/questions/max_rent_value_check_spec.rb b/spec/models/form/lettings/questions/max_rent_value_check_spec.rb deleted file mode 100644 index 6fa0784e4..000000000 --- a/spec/models/form/lettings/questions/max_rent_value_check_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Lettings::Questions::MaxRentValueCheck, type: :model do - subject(:question) { described_class.new(nil, question_definition, page, check_answers_card_number:) } - - let(:question_definition) { nil } - let(:check_answers_card_number) { nil } - let(:page) { instance_double(Form::Page) } - - it "has correct page" do - expect(question.page).to eq(page) - end - - it "has the correct id" do - expect(question.id).to eq("rent_value_check") - end - - it "has the correct type" do - expect(question.type).to eq("interruption_screen") - end - - it "has the correct answer_options" do - expect(question.answer_options).to eq({ - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }) - end - - it "has the correct hidden_in_check_answers" do - expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "rent_value_check" => 0 }, { "rent_value_check" => 1 }] }) - end -end diff --git a/spec/models/form/lettings/questions/min_rent_value_check_spec.rb b/spec/models/form/lettings/questions/min_rent_value_check_spec.rb deleted file mode 100644 index c3d8a16bc..000000000 --- a/spec/models/form/lettings/questions/min_rent_value_check_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Lettings::Questions::MinRentValueCheck, type: :model do - subject(:question) { described_class.new(nil, question_definition, page, check_answers_card_number:) } - - let(:question_definition) { nil } - let(:check_answers_card_number) { nil } - let(:page) { instance_double(Form::Page) } - - it "has correct page" do - expect(question.page).to eq(page) - end - - it "has the correct id" do - expect(question.id).to eq("rent_value_check") - end - - it "has the correct type" do - expect(question.type).to eq("interruption_screen") - end - - it "has the correct answer_options" do - expect(question.answer_options).to eq({ - "0" => { "value" => "Yes" }, - "1" => { "value" => "No" }, - }) - end - - it "has the correct hidden_in_check_answers" do - expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "rent_value_check" => 0 }, { "rent_value_check" => 1 }] }) - end -end diff --git a/spec/models/form/lettings/subsections/income_and_benefits_spec.rb b/spec/models/form/lettings/subsections/income_and_benefits_spec.rb index c260ff56d..4c92faaf6 100644 --- a/spec/models/form/lettings/subsections/income_and_benefits_spec.rb +++ b/spec/models/form/lettings/subsections/income_and_benefits_spec.rb @@ -30,8 +30,7 @@ RSpec.describe Form::Lettings::Subsections::IncomeAndBenefits, type: :model do rent_bi_weekly rent_4_weekly rent_monthly - brent_min_rent_value_check - brent_max_rent_value_check + brent_rent_value_check scharge_value_check pscharge_value_check supcharg_value_check diff --git a/spec/models/form/lettings/subsections/property_information_spec.rb b/spec/models/form/lettings/subsections/property_information_spec.rb index 7d406d1a7..d333ff669 100644 --- a/spec/models/form/lettings/subsections/property_information_spec.rb +++ b/spec/models/form/lettings/subsections/property_information_spec.rb @@ -17,36 +17,6 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do allow(form).to receive(:start_year_after_2024?).and_return(false) end - context "when 2022" do - let(:start_date) { Time.utc(2022, 2, 8) } - - it "has correct pages" do - expect(property_information.pages.compact.map(&:id)).to eq( - %w[ - property_postcode - property_local_authority - local_authority_min_rent_value_check - local_authority_max_rent_value_check - first_time_property_let_as_social_housing - property_let_type - property_vacancy_reason_not_first_let - property_vacancy_reason_first_let - property_number_of_times_relet - property_unit_type - property_building_type - property_wheelchair_accessible - property_number_of_bedrooms - beds_min_rent_value_check - beds_max_rent_value_check - void_date - void_date_value_check - property_major_repairs - property_major_repairs_value_check - ], - ) - end - end - context "when 2023" do let(:start_date) { Time.utc(2023, 2, 8) } @@ -57,8 +27,7 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do uprn_confirmation address property_local_authority - local_authority_min_rent_value_check - local_authority_max_rent_value_check + local_authority_rent_value_check first_time_property_let_as_social_housing property_let_type property_vacancy_reason_not_first_let @@ -68,8 +37,7 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do property_building_type property_wheelchair_accessible property_number_of_bedrooms - beds_min_rent_value_check - beds_max_rent_value_check + beds_rent_value_check void_date void_date_value_check property_major_repairs @@ -96,8 +64,7 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do uprn_selection address property_local_authority - local_authority_min_rent_value_check - local_authority_max_rent_value_check + local_authority_rent_value_check first_time_property_let_as_social_housing property_let_type property_vacancy_reason_not_first_let @@ -106,8 +73,7 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do property_building_type property_wheelchair_accessible property_number_of_bedrooms - beds_min_rent_value_check - beds_max_rent_value_check + beds_rent_value_check void_date void_date_value_check property_major_repairs diff --git a/spec/services/documentation_generator_spec.rb b/spec/services/documentation_generator_spec.rb index 47bc813f7..6f4714d01 100644 --- a/spec/services/documentation_generator_spec.rb +++ b/spec/services/documentation_generator_spec.rb @@ -89,7 +89,7 @@ describe DocumentationGenerator do end describe ":describe_soft_validations" do - let(:all_validation_methods) { ["rent_in_soft_min_range?"] } + let(:all_validation_methods) { ["rent_soft_validation_triggered?"] } let(:response) do { "choices" => [{ "message" => { "tool_calls" => [{ "function" => { "arguments" => "{\n \"description\": \"Validates the format.\",\n \"validation_type\": \"format\",\n \"other_validated_models\": \"User\"}" } }] } }] } @@ -100,7 +100,7 @@ describe DocumentationGenerator do it "creates new validation documentation records" do expect { described_class.new.describe_soft_validations(client, all_validation_methods, all_helper_methods, log_type) }.to change(LogValidation, :count) - expect(LogValidation.where(validation_name: "rent_in_soft_min_range?").count).to be_positive + expect(LogValidation.where(validation_name: "rent_soft_validation_triggered?").count).to be_positive any_validation = LogValidation.first expect(any_validation.description).to eq("Validates the format.") expect(any_validation.field).not_to be_empty