diff --git a/app/helpers/interruption_screen_helper.rb b/app/helpers/interruption_screen_helper.rb new file mode 100644 index 000000000..cb2c493ef --- /dev/null +++ b/app/helpers/interruption_screen_helper.rb @@ -0,0 +1,23 @@ +module InterruptionScreenHelper + def display_informative_text(informative_text, case_log) + return "" unless informative_text["arguments"] + + translation_params = {} + informative_text["arguments"].each do |argument| + value = if argument["label"] + case_log.form.get_question(argument["key"], case_log).answer_label(case_log).downcase + else + case_log.public_send(argument["key"]) + end + translation_params[argument["i18n_template"].to_sym] = value + end + + begin + translation = I18n.t(informative_text["translation"], **translation_params) + translation.to_s.html_safe + rescue I18n::MissingInterpolationArgument => e + Rails.logger.error(e.message) + "" + end + end +end diff --git a/app/helpers/interuption_screen_helper.rb b/app/helpers/interuption_screen_helper.rb deleted file mode 100644 index 393134f83..000000000 --- a/app/helpers/interuption_screen_helper.rb +++ /dev/null @@ -1,13 +0,0 @@ -module InteruptionScreenHelper - def display_informative_text(informative_text, case_log) - arguments = informative_text["argument"].map { |x, type| type == "question" ? case_log.form.get_question(x, case_log).answer_label(case_log) : case_log.public_send(x) } - keys = informative_text["argument"].keys - - begin - translation = I18n.t(informative_text["translation"], keys[0].present? ? keys[0].to_sym : "" => arguments[0], keys[1].present? ? keys[1].to_sym : "" => arguments[1], keys[2].present? ? keys[2].to_sym : "" => arguments[2]) - rescue StandardError - return "" - end - translation.to_s.html_safe - end -end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index d168f5740..1452a1d35 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -58,6 +58,7 @@ class CaseLog < ApplicationRecord 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 + RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze enum status: STATUS def form @@ -375,6 +376,18 @@ class CaseLog < ApplicationRecord OPTIONAL_FIELDS + dynamically_not_required end + (1..8).each do |person_num| + define_method("retirement_age_for_person_#{person_num}") do + retirement_age_for_person(person_num) + end + end + + def retirement_age_for_person(person_num) + gender = public_send("sex#{person_num}".to_sym) + return unless gender + RETIREMENT_AGES[gender] + end + private PIO = Postcodes::IO.new diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index b5397a4f9..a48f775dc 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -45,7 +45,7 @@ module Validations::HouseholdValidations (2..8).each do |n| validate_person_age_matches_economic_status(record, n) validate_person_age_matches_relationship(record, n) - validate_person_age_and_gender_match_economic_status(record, n) + # validate_person_age_and_gender_match_economic_status(record, n) validate_person_age_and_relationship_matches_economic_status(record, n) end validate_partner_count(record) @@ -146,10 +146,10 @@ private economic_status = record.public_send("ecstat#{person_num}") return unless age && economic_status - if age > 70 && !tenant_is_retired?(economic_status) - record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_over_70", person_num:) - record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_over_70", person_num:) - end + # if age > 70 && !tenant_is_retired?(economic_status) + # record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_over_70", person_num:) + # record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_over_70", person_num:) + # end if age < 16 && !tenant_is_economic_child?(economic_status) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:) @@ -184,23 +184,23 @@ private end end - def validate_person_age_and_gender_match_economic_status(record, person_num) - age = record.public_send("age#{person_num}") - gender = record.public_send("sex#{person_num}") - economic_status = record.public_send("ecstat#{person_num}") - return unless age && economic_status && gender - - if gender == "M" && tenant_is_retired?(economic_status) && age < 65 - record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_male") - record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_male") - record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_male") - end - if gender == "F" && tenant_is_retired?(economic_status) && age < 60 - record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_female") - record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_female") - record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_female") - end - end + # def validate_person_age_and_gender_match_economic_status(record, person_num) + # age = record.public_send("age#{person_num}") + # gender = record.public_send("sex#{person_num}") + # economic_status = record.public_send("ecstat#{person_num}") + # return unless age && economic_status && gender + # + # if gender == "M" && tenant_is_retired?(economic_status) && age < 65 + # record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_male") + # record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_male") + # record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_male") + # end + # if gender == "F" && tenant_is_retired?(economic_status) && age < 60 + # record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_female") + # record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_female") + # record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_female") + # end + # end def validate_partner_count(record) partner_count = (2..8).count { |n| tenant_is_partner?(record["relat#{n}"]) } @@ -209,10 +209,6 @@ private end end - def tenant_is_retired?(economic_status) - economic_status == 5 - end - def tenant_is_economic_child?(economic_status) economic_status == 9 end diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 739649dd4..a2d8c13a0 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -38,4 +38,38 @@ module Validations::SoftValidations rent_range = LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:) rent_range.present? && weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max) end + + (1..8).each do |person_num| + define_method("person_#{person_num}_retired_under_soft_min_age?") do + retired_under_soft_min_age?(person_num) + end + define_method("person_#{person_num}_not_retired_over_soft_max_age?") do + not_retired_over_soft_max_age?(person_num) + end + end + +private + + def tenant_is_retired?(economic_status) + economic_status == 5 + end + + def retired_under_soft_min_age?(person_num) + age = public_send("age#{person_num}") + economic_status = public_send("ecstat#{person_num}") + gender = public_send("sex#{person_num}") + return unless age && economic_status && gender + + %w[M X].include?(gender) && tenant_is_retired?(economic_status) && age < 67 || + gender == "F" && tenant_is_retired?(economic_status) && age < 60 + end + + def not_retired_over_soft_max_age?(person_num) + age = public_send("age#{person_num}") + economic_status = public_send("ecstat#{person_num}") + gender = public_send("sex#{person_num}") + return unless age && economic_status && gender + %w[M X].include?(gender) && !tenant_is_retired?(economic_status) && age > 67 || + gender == "F" && !tenant_is_retired?(economic_status) && age > 60 + end end diff --git a/app/views/form/_interruption_screen_question.html.erb b/app/views/form/_interruption_screen_question.html.erb index 8913aa1e7..427cff471 100644 --- a/app/views/form/_interruption_screen_question.html.erb +++ b/app/views/form/_interruption_screen_question.html.erb @@ -1,8 +1,8 @@ <%= govuk_panel( - title_text:, + title_text: I18n.t(title_text), classes: "app-panel--interruption", ) do %> - <%= display_informative_text(informative_text, case_log) %> +
<%= display_informative_text(informative_text, case_log) %>
<%= f.govuk_radio_buttons_fieldset question.id.to_sym, legend: { text: question.header }, hint: { text: question.hint_text&.html_safe } do %> diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 422ec5dd1..09d26c342 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1529,6 +1529,72 @@ } } }, + "lead_tenant_under_retirement_value_check": { + "depends_on": [{ "person_1_retired_under_soft_min_age?": true }], + "title_text": "soft_validations.retirement.min.title", + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_1", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "lead_tenant_over_retirement_value_check": { + "depends_on": [{ "person_1_not_retired_over_soft_max_age?": true }], + "title_text": "soft_validations.retirement.max.title", + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "sex1", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_1", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "person_2_known": { "header": "You’ve given us the details for 1 person in the household", "description": "", @@ -1754,6 +1820,72 @@ } ] }, + "person_2_under_retirement_value_check": { + "depends_on": [{ "person_2_retired_under_soft_min_age?": true }], + "title_text": "soft_validations.retirement.min.title", + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "sex2", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_2", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "person_2_over_retirement_value_check": { + "depends_on": [{ "person_2_not_retired_over_soft_max_age?": true }], + "title_text": "soft_validations.retirement.max.title", + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "sex2", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_2", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "person_3_known": { "header": "You’ve given us the details for 2 people in the household", "description": "", @@ -1965,6 +2097,7 @@ } } }, + "depends_on": [ { "details_known_3": 0, @@ -1976,6 +2109,72 @@ } ] }, + "person_3_under_retirement_value_check": { + "depends_on": [{ "person_3_retired_under_soft_min_age?": true }], + "title_text": "soft_validations.retirement.min.title", + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "sex3", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_3", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "person_3_over_retirement_value_check": { + "depends_on": [{ "person_3_not_retired_over_soft_max_age?": true }], + "title_text": "soft_validations.retirement.max.title", + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "sex3", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_3", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "person_4_known": { "header": "You’ve given us the details for 3 people in the household", "description": "", @@ -2011,7 +2210,7 @@ "hhmemb": 8 } ] - }, + }, "person_4_relationship_to_lead": { "header": "", "description": "", @@ -2195,6 +2394,72 @@ } ] }, + "person_4_under_retirement_value_check": { + "depends_on": [{ "person_4_retired_under_soft_min_age?": true }], + "title_text": "soft_validations.retirement.min.title", + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "sex4", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_4", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "person_4_over_retirement_value_check": { + "depends_on": [{ "person_4_not_retired_over_soft_max_age?": true }], + "title_text": "soft_validations.retirement.max.title", + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "sex4", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_4", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "person_5_known": { "header": "You’ve given us the details for 4 people in the household", "description": "", @@ -2411,6 +2676,72 @@ } ] }, + "person_5_under_retirement_value_check": { + "depends_on": [{ "person_5_retired_under_soft_min_age?": true }], + "title_text": "soft_validations.retirement.min.title", + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "sex5", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_5", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "person_5_over_retirement_value_check": { + "depends_on": [{ "person_5_not_retired_over_soft_max_age?": true }], + "title_text": "soft_validations.retirement.max.title", + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "sex5", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_5", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "person_6_known": { "header": "You’ve given us the details for 5 people in the household", "description": "", @@ -2624,6 +2955,72 @@ } ] }, + "person_6_under_retirement_value_check": { + "depends_on": [{ "person_6_retired_under_soft_min_age?": true }], + "title_text": "soft_validations.retirement.min.title", + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "sex6", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_6", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "person_6_over_retirement_value_check": { + "depends_on": [{ "person_6_not_retired_over_soft_max_age?": true }], + "title_text": "soft_validations.retirement.max.title", + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "sex6", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_6", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "person_7_known": { "header": "You’ve given us the details for 7 people in the household", "description": "", @@ -2834,6 +3231,72 @@ } ] }, + "person_7_under_retirement_value_check": { + "depends_on": [{ "person_7_retired_under_soft_min_age?": true }], + "title_text": "soft_validations.retirement.min.title", + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "sex7", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_7", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "person_7_over_retirement_value_check": { + "depends_on": [{ "person_7_not_retired_over_soft_max_age?": true }], + "title_text": "soft_validations.retirement.max.title", + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "sex7", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_7", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, "person_8_known": { "header": "You’ve given us the details for 7 people in the household", "description": "", @@ -3040,6 +3503,72 @@ "age8": null } ] + }, + "person_8_under_retirement_value_check": { + "depends_on": [{ "person_8_retired_under_soft_min_age?": true }], + "title_text": "soft_validations.retirement.min.title", + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "sex8", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_8", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } + }, + "person_8_over_retirement_value_check": { + "depends_on": [{ "person_8_not_retired_over_soft_max_age?": true }], + "title_text": "soft_validations.retirement.max.title", + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "sex8", + "label": true, + "i18n_template": "gender" + }, + { + "key": "retirement_age_for_person_8", + "label": false, + "i18n_template": "age" + }] + }, + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this is correct?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } } } }, @@ -4634,10 +5163,18 @@ }, "net_income_value_check": { "depends_on": [{ "net_income_soft_validation_triggered?": true }], - "title_text": "Net income is outside the expected range based on the lead tenant’s working situation", + "title_text": "soft_validations.net_income.title_text", "informative_text": { "translation": "soft_validations.net_income.hint_text", - "argument": {"ecstat1": "question", "earnings": "question"} + "arguments": [{ + "key": "ecstat1", + "label": true, + "i18n_template": "ecstat1" + }, + {"key": "earnings", + "label": true, + "i18n_template": "earnings" + }] }, "questions": { "net_income_value_check": { @@ -5628,7 +6165,23 @@ "depends_on": [{ "rent_in_soft_min_range?": true }], "informative_text": { "translation": "soft_validations.rent.min.hint_text", - "argument": {"la": "question", "soft_min_for_period": "method", "brent":"question"} + "arguments": [ + { + "key": "la", + "label": true, + "i18n_template": "la" + }, + { + "key": "soft_min_for_period", + "label": false, + "i18n_template": "soft_min_for_period" + }, + { + "key":"brent", + "label": true, + "i18n_template": "brent" + } + ] }, "questions": { "rent_value_check": { @@ -5651,7 +6204,23 @@ "depends_on": [{ "rent_in_soft_max_range?": true }], "informative_text": { "translation": "soft_validations.rent.max.hint_text", - "argument": {"la": "question", "soft_max_for_period": "method", "brent":"question"} + "arguments": [ + { + "key": "la", + "label": true, + "i18n_template": "la" + }, + { + "key": "soft_max_for_period", + "label": false, + "i18n_template": "soft_max_for_period" + }, + { + "key":"brent", + "label": true, + "i18n_template": "brent" + } + ] }, "questions": { "rent_value_check": { diff --git a/config/locales/en.yml b/config/locales/en.yml index fa6d731ff..c40ef0535 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -223,13 +223,14 @@ en: cannot_be_internal_transfer: "Answer cannot be internal transfer as you already told us this is not a secure tenancy" not_joint: "This cannot be a joint tenancy as you've told us there's only one person in the household" joint_more_than_one_member: "There must be more than one person in the household as you've told us this is a joint tenancy" - + declaration: missing: "You must show the DLUHC privacy notice to the tenant before you can submit this log." soft_validations: net_income: + title_text: "Net income is outside the expected range based on the lead tenant’s working situation" hint_text: "You told us the lead tenant’s working situation is: %{ecstat1}.
The household income you have entered is %{earnings}.
" in_soft_min_range: message: "Net income is lower than expected based on the lead tenant’s working situation. Are you sure this is correct?" @@ -240,6 +241,14 @@ en: hint_text: "The minimum rent for this type of property in %{la} is £%{soft_min_for_period}.
" max: hint_text: "The maximum rent for this type of property in %{la} is £%{soft_max_for_period}.
" + retirement: + min: + title: "Age is below the expected range based on the person being retired" + hint_text: "This person cannot be retired as you told us they're %{gender} and under %{age}" + max: + title: "Age is above the expected range based on the person not being retired" + hint_text: "This person must be retired as you told us they're %{gender} and over %{age}" + devise: two_factor_authentication: success: "Two-factor authentication successful" diff --git a/db/migrate/20220509110842_add_retirement_value_check.rb b/db/migrate/20220509110842_add_retirement_value_check.rb new file mode 100644 index 000000000..ac16f4a5e --- /dev/null +++ b/db/migrate/20220509110842_add_retirement_value_check.rb @@ -0,0 +1,5 @@ +class AddRetirementValueCheck < ActiveRecord::Migration[7.0] + def change + add_column :case_logs, :retirement_value_check, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index d63efc676..2407bfbdb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -224,6 +224,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_05_11_114334) do t.integer "illness_type_0" t.integer "tshortfall_known" t.integer "shelteredaccom" + t.integer "retirement_value_check" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true diff --git a/spec/helpers/interruption_screen_helper_spec.rb b/spec/helpers/interruption_screen_helper_spec.rb new file mode 100644 index 000000000..885425dac --- /dev/null +++ b/spec/helpers/interruption_screen_helper_spec.rb @@ -0,0 +1,99 @@ +require "rails_helper" + +RSpec.describe InterruptionScreenHelper do + form_handler = FormHandler.instance + let(:form) { form_handler.get_form("test_form") } + let(:subsection) { form.get_subsection("household_characteristics") } + let(:user) { FactoryBot.create(:user) } + let(:case_log) do + FactoryBot.create( + :case_log, + :in_progress, + ecstat1: 1, + earnings: 750, + incfreq: 1, + owning_organisation: user.organisation, + managing_organisation: user.organisation, + ) + end + + describe "display_informative_text" do + context "when 2 out of 2 arguments are given" do + it "returns correct informative text" do + informative_text = { + "translation" => "soft_validations.net_income.hint_text", + "arguments" => [ + { + "key" => "ecstat1", + "label" => true, + "i18n_template" => "ecstat1", + }, + { + "key" => "earnings", + "label" => true, + "i18n_template" => "earnings", + }, + ], + } + expect(display_informative_text(informative_text, case_log)) + .to eq("You told us the lead tenant’s working situation is: Full-time – 30 hours or more.
The household income you have entered is £750.00 every week.
") + end + end + + context "when 1 out of 1 arguments is given" do + it "returns correct informative text" do + informative_text = { + "translation" => "test.one_argument", + "arguments" => [ + { + "key" => "ecstat1", + "label" => true, + "i18n_template" => "ecstat1", + }, + ], + } + expect(display_informative_text(informative_text, case_log)) + .to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more") + end + end + + context "when 2 out of 1 arguments are given" do + it "returns correct informative text" do + informative_text = { + "translation" => "test.one_argument", + "arguments" => [ + { + "key" => "ecstat1", + "label" => true, + "i18n_template" => "ecstat1", + }, + { + "key" => "earnings", + "label" => true, + "i18n_template" => "earnings", + }, + ], + } + expect(display_informative_text(informative_text, case_log)) + .to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more") + end + end + + context "when 1 out of 2 arguments are given" do + it "returns an empty string" do + informative_text = { + "translation" => "soft_validations.net_income.hint_text", + "arguments" => [ + { + "key" => "ecstat1", + "label" => true, + "i18n_template" => "ecstat1", + }, + ], + } + expect(display_informative_text(informative_text, case_log)) + .to eq("") + end + end + end +end diff --git a/spec/helpers/interuption_screen_helper_spec.rb b/spec/helpers/interuption_screen_helper_spec.rb deleted file mode 100644 index 7174fb82f..000000000 --- a/spec/helpers/interuption_screen_helper_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -require "rails_helper" - -RSpec.describe InteruptionScreenHelper do - form_handler = FormHandler.instance - let(:form) { form_handler.get_form("test_form") } - let(:subsection) { form.get_subsection("household_characteristics") } - let(:user) { FactoryBot.create(:user) } - let(:case_log) do - FactoryBot.create( - :case_log, - :in_progress, - ecstat1: 1, - earnings: 750, - incfreq: 1, - owning_organisation: user.organisation, - managing_organisation: user.organisation, - ) - end - - describe "display_informative_text" do - context "when 2 out of 2 arguments are given" do - it "returns correct informative text" do - informative_text = { - "translation" => "soft_validations.net_income.hint_text", - "argument" => { "ecstat1": "question", "earnings": "question" }, - } - expect(display_informative_text(informative_text, case_log)) - .to eq("You told us the lead tenant’s working situation is: Full-time – 30 hours or more.
The household income you have entered is £750.00 every week.
") - end - end - - context "when 1 out of 1 arguments is given" do - it "returns correct informative text" do - informative_text = { - "translation" => "test.one_argument", - "argument" => { "ecstat1": "question" }, - } - expect(display_informative_text(informative_text, case_log)) - .to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more") - end - end - end - - context "when 2 out of 1 arguments are given" do - it "returns correct informative text" do - informative_text = { - "translation" => "test.one_argument", - "argument" => { "ecstat1": "question", "earnings": "question" }, - } - expect(display_informative_text(informative_text, case_log)) - .to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more") - end - end - - context "when 1 out of 2 arguments are given" do - it "returns an empty string" do - informative_text = { - "translation" => "soft_validations.net_income.hint_text", - "argument" => { "ecstat1": "question" }, - } - expect(display_informative_text(informative_text, case_log)) - .to eq("") - end - end -end