From 868de89234bf51fcdcdc69641ed5d496727334ff Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 7 Apr 2022 09:45:01 +0100 Subject: [PATCH] Update soft rent validations messages (#453) * Update soft rent validations messages * fix suffix and to_s for check_answers symbol * rubocop --- app/controllers/form_controller.rb | 2 +- app/models/case_log.rb | 18 +++++++ .../validations/financial_validations.rb | 3 +- config/forms/2021_2022.json | 6 +-- config/locales/en.yml | 14 +++--- spec/models/case_log_spec.rb | 47 +++++++++++++++++++ 6 files changed, 78 insertions(+), 12 deletions(-) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 787017186..15a265b33 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -8,7 +8,7 @@ class FormController < ApplicationController @page = @case_log.form.get_page(params[:case_log][:page]) responses_for_page = responses_for_page(@page) if @case_log.update(responses_for_page) - if is_referrer_check_answers? + if is_referrer_check_answers? && !@case_log.form.next_page(@page, @case_log).to_s.include?("value_check") redirect_to(send("case_log_#{@case_log.form.subsection_for_page(@page).id}_check_answers_path", @case_log)) elsif @case_log.form.is_last_question?(@page, @case_log.form.subsection_for_page(@page), @case_log) redirect_to(case_logs_path) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 755615e8b..ef9f5a91a 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -42,6 +42,7 @@ class CaseLog < ApplicationRecord HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze + SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze enum status: STATUS def form @@ -289,6 +290,16 @@ class CaseLog < ApplicationRecord end end + def soft_min_for_period + soft_min = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:).soft_min + "#{soft_value_for_period(soft_min)} #{SUFFIX_FROM_PERIOD[period].presence || 'every week'}" + end + + def soft_max_for_period + soft_max = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:).soft_max + "#{soft_value_for_period(soft_max)} #{SUFFIX_FROM_PERIOD[period].presence || 'every week'}" + end + private PIO = Postcodes::IO.new @@ -578,4 +589,11 @@ private def ecstat_refused? [ecstat1, ecstat2, ecstat3, ecstat4, ecstat5, ecstat6, ecstat7, ecstat8].any?(10) end + + def soft_value_for_period(value) + num_of_weeks = NUM_OF_WEEKS_FROM_PERIOD[period] + return "" unless value && num_of_weeks + + (value * 52 / num_of_weeks).round(2) + end end diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index a1c2df78f..c68788003 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -138,12 +138,13 @@ private collection_year = record.collection_start_year rent_range = LaRentRange.find_by(start_year: collection_year, la: record.la, beds: record.beds, lettype: record.lettype) - if rent_range.present? && !weekly_value_in_range(record, "brent", rent_range.hard_min, rent_range.hard_max) && record.brent.present? + if rent_range.present? && !weekly_value_in_range(record, "brent", rent_range.hard_min, rent_range.hard_max) && record.brent.present? && record.period.present? record.errors.add :brent, I18n.t("validations.financial.brent.not_in_range") record.errors.add :beds, I18n.t("validations.financial.brent.beds.not_in_range") record.errors.add :la, I18n.t("validations.financial.brent.la.not_in_range") record.errors.add :rent_type, I18n.t("validations.financial.brent.rent_type.not_in_range") record.errors.add :needstype, I18n.t("validations.financial.brent.needstype.not_in_range") + record.errors.add :period, I18n.t("validations.financial.brent.period.not_in_range") end end end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index ae249530c..0b92bf3b2 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -5549,10 +5549,9 @@ }, "min_rent_value_check": { "depends_on": [{ "rent_in_soft_min_range?": true }], - "title_text": "Rent value is outside of the expected range", "informative_text": { "translation": "soft_validations.rent.min.hint_text", - "argument": {"la": "question", "soft_min": "method", "brent":"question"} + "argument": {"la": "question", "soft_min_for_period": "method", "brent":"question"} }, "questions": { "rent_value_check": { @@ -5573,10 +5572,9 @@ }, "max_rent_value_check": { "depends_on": [{ "rent_in_soft_max_range?": true }], - "title_text": "Rent value is outside of the expected range", "informative_text": { "translation": "soft_validations.rent.max.hint_text", - "argument": {"la": "question", "soft_max": "method", "brent":"question"} + "argument": {"la": "question", "soft_max_for_period": "method", "brent":"question"} }, "questions": { "rent_value_check": { diff --git a/config/locales/en.yml b/config/locales/en.yml index 984570b21..91cdfa7e2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -128,6 +128,8 @@ en: not_in_range: "Basic rent is outside of the expected range based on this lettings type" rent_type: not_in_range: "Basic rent is outside of the expected range based on this lettings type" + period: + not_in_range: "Basic rent is outside of the expected range based on this period" charges: complete_1_of_3: "Answer only one of the following questions: 'total charges', 'care home charges' or 'does the household pay rent or charges?'" tcharge: @@ -153,10 +155,10 @@ en: retired_male: "Male tenant who is retired must be 65 or over" retired_female: "Female tenant who is retired must be 60 or over" retired_over_70: 'Answer cannot be over 70 as as tenant %{person_num} has economic status that is not "Retired"' - child_under_16_relat: 'Answer cannot be under 16 as tenant %{person_num} is not a child of the lead tenant' + child_under_16_relat: "Answer cannot be under 16 as tenant %{person_num} is not a child of the lead tenant" child_under_16: "Answer cannot be under 16 as tenant's %{person_num} working situation is not 'child under 16'" child_over_16: "Answer cannot be over 16 as tenant's %{person_num} working situation is 'child under 16'" - student_16_19: 'Answer cannot be between 16 and 19 as tenant %{person_num} is a child of the lead tenant but is not a full-time student' + student_16_19: "Answer cannot be between 16 and 19 as tenant %{person_num} is a child of the lead tenant but is not a full-time student" lead: over_20: "Lead tenant must be under 20 as you told us that their housing situation immediately before this letting was a children's home or foster care" ecstat: @@ -225,10 +227,10 @@ en: in_soft_max_range: message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" rent: - min: - hint_text: "

The minimum rent for a property in %{la} is £%{soft_min} every week.

You entered %{brent}

" - max: - hint_text: "

The maximum rent for a property in %{la} is £%{soft_max} every week.

You entered %{brent}

" + min: + hint_text: "

You told us the rent is %{brent}

The minimum rent for this type of property in %{la} is £%{soft_min_for_period}

" + max: + hint_text: "

You told us the rent is %{brent}

The maximum rent for this type of property in %{la} is £%{soft_max_for_period}

" devise: two_factor_authentication: success: "Two factor authentication successful." diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 729a3f457..b648f27f2 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1778,4 +1778,51 @@ RSpec.describe CaseLog do expect(case_log.paper_trail.previous_version.age1).to eq(17) end end + + describe "soft values for period" do + let(:case_log) { FactoryBot.create(:case_log) } + + before do + LaRentRange.create!( + ranges_rent_id: "1", + la: "E07000223", + beds: 1, + lettype: 1, + soft_min: 100, + soft_max: 400, + hard_min: 50, + hard_max: 500, + start_year: 2021, + ) + + case_log.la = "E07000223" + case_log.lettype = 1 + case_log.beds = 1 + case_log.startdate = Time.zone.local(2021, 10, 10) + end + + context "when period is weekly for 52 weeks" do + it "returns weekly soft min for 52 weeks" do + case_log.period = 1 + expect(case_log.soft_min_for_period).to eq("100.0 every week") + end + + it "returns weekly soft max for 52 weeks" do + case_log.period = 1 + expect(case_log.soft_max_for_period).to eq("400.0 every week") + end + end + + context "when period is weekly for 47 weeks" do + it "returns weekly soft min for 47 weeks" do + case_log.period = 8 + expect(case_log.soft_min_for_period).to eq("110.64 every week") + end + + it "returns weekly soft max for 47 weeks" do + case_log.period = 8 + expect(case_log.soft_max_for_period).to eq("442.55 every week") + end + end + end end