Browse Source

Update soft rent validations messages (#453)

* Update soft rent validations messages

* fix suffix and to_s for check_answers symbol

* rubocop
pull/456/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
868de89234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/form_controller.rb
  2. 18
      app/models/case_log.rb
  3. 3
      app/models/validations/financial_validations.rb
  4. 6
      config/forms/2021_2022.json
  5. 14
      config/locales/en.yml
  6. 47
      spec/models/case_log_spec.rb

2
app/controllers/form_controller.rb

@ -8,7 +8,7 @@ class FormController < ApplicationController
@page = @case_log.form.get_page(params[:case_log][:page]) @page = @case_log.form.get_page(params[:case_log][:page])
responses_for_page = responses_for_page(@page) responses_for_page = responses_for_page(@page)
if @case_log.update(responses_for_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)) 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) elsif @case_log.form.is_last_question?(@page, @case_log.form.subsection_for_page(@page), @case_log)
redirect_to(case_logs_path) redirect_to(case_logs_path)

18
app/models/case_log.rb

@ -42,6 +42,7 @@ class CaseLog < ApplicationRecord
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.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 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 enum status: STATUS
def form def form
@ -289,6 +290,16 @@ class CaseLog < ApplicationRecord
end end
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 private
PIO = Postcodes::IO.new PIO = Postcodes::IO.new
@ -578,4 +589,11 @@ private
def ecstat_refused? def ecstat_refused?
[ecstat1, ecstat2, ecstat3, ecstat4, ecstat5, ecstat6, ecstat7, ecstat8].any?(10) [ecstat1, ecstat2, ecstat3, ecstat4, ecstat5, ecstat6, ecstat7, ecstat8].any?(10)
end 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 end

3
app/models/validations/financial_validations.rb

@ -138,12 +138,13 @@ private
collection_year = record.collection_start_year collection_year = record.collection_start_year
rent_range = LaRentRange.find_by(start_year: collection_year, la: record.la, beds: record.beds, lettype: record.lettype) 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 :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 :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 :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 :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 :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 end
end end

6
config/forms/2021_2022.json

@ -5549,10 +5549,9 @@
}, },
"min_rent_value_check": { "min_rent_value_check": {
"depends_on": [{ "rent_in_soft_min_range?": true }], "depends_on": [{ "rent_in_soft_min_range?": true }],
"title_text": "Rent value is outside of the expected range",
"informative_text": { "informative_text": {
"translation": "soft_validations.rent.min.hint_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": { "questions": {
"rent_value_check": { "rent_value_check": {
@ -5573,10 +5572,9 @@
}, },
"max_rent_value_check": { "max_rent_value_check": {
"depends_on": [{ "rent_in_soft_max_range?": true }], "depends_on": [{ "rent_in_soft_max_range?": true }],
"title_text": "Rent value is outside of the expected range",
"informative_text": { "informative_text": {
"translation": "soft_validations.rent.max.hint_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": { "questions": {
"rent_value_check": { "rent_value_check": {

14
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" not_in_range: "Basic rent is outside of the expected range based on this lettings type"
rent_type: rent_type:
not_in_range: "Basic rent is outside of the expected range based on this lettings 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: 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?'" 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: tcharge:
@ -153,10 +155,10 @@ en:
retired_male: "Male tenant who is retired must be 65 or over" 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_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"' 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_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'" 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: 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" 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: ecstat:
@ -225,10 +227,10 @@ en:
in_soft_max_range: 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?" message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?"
rent: rent:
min: min:
hint_text: "<p>The minimum rent for a property in %{la} is £%{soft_min} every week.</p><p>You entered <strong>%{brent}</strong></p>" hint_text: "<h1 class=\"govuk-heading-l app-panel--interruption\">You told us the rent is %{brent}</h1><p>The minimum rent for this type of property in %{la} is £%{soft_min_for_period}</p>"
max: max:
hint_text: "<p>The maximum rent for a property in %{la} is £%{soft_max} every week.</p><p>You entered <strong>%{brent}</strong></p>" hint_text: "<h1 class=\"govuk-heading-l app-panel--interruption\">You told us the rent is %{brent}</h1><p>The maximum rent for this type of property in %{la} is £%{soft_max_for_period}</p>"
devise: devise:
two_factor_authentication: two_factor_authentication:
success: "Two factor authentication successful." success: "Two factor authentication successful."

47
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) expect(case_log.paper_trail.previous_version.age1).to eq(17)
end end
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 end

Loading…
Cancel
Save