From 970c9afcf7f27e82ad92908d1f9effe3c062d2be Mon Sep 17 00:00:00 2001 From: Ted-U <92022120+Ted-U@users.noreply.github.com> Date: Fri, 13 May 2022 13:20:49 +0100 Subject: [PATCH] Cldc 1217 retirement soft validation (#570) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Interruption screen refactor * Add test for retirement_age_for_person Co-authored-by: Stéphane Meny * Rubocop * update 22-23 form * fix failures * lint fixes * remove whitespace * remove commented code * make spec file use translations instead of content * update content * lint fixes * fix typo * fix question wording * fix failing spec * add full stop Co-authored-by: Stéphane Meny Co-authored-by: Dushan Despotovic --- app/helpers/interruption_screen_helper.rb | 41 + app/helpers/interuption_screen_helper.rb | 13 - app/models/case_log.rb | 29 + .../validations/household_validations.rb | 27 - app/models/validations/soft_validations.rb | 35 + .../_interruption_screen_question.html.erb | 4 +- config/forms/2021_2022.json | 700 ++++++++++++++++- config/forms/2022_2023.json | 715 +++++++++++++++++- config/locales/en.yml | 14 +- ...220509110842_add_retirement_value_check.rb | 5 + db/schema.rb | 1 + spec/features/form/validations_spec.rb | 2 +- spec/fixtures/exports/case_logs.xml | 1 + spec/fixtures/forms/2021_2022.json | 16 +- .../interruption_screen_helper_spec.rb | 126 +++ .../helpers/interuption_screen_helper_spec.rb | 65 -- spec/models/case_log_spec.rb | 34 + .../validations/household_validations_spec.rb | 36 - 18 files changed, 1676 insertions(+), 188 deletions(-) create mode 100644 app/helpers/interruption_screen_helper.rb delete mode 100644 app/helpers/interuption_screen_helper.rb create mode 100644 db/migrate/20220509110842_add_retirement_value_check.rb create mode 100644 spec/helpers/interruption_screen_helper_spec.rb delete mode 100644 spec/helpers/interuption_screen_helper_spec.rb diff --git a/app/helpers/interruption_screen_helper.rb b/app/helpers/interruption_screen_helper.rb new file mode 100644 index 000000000..cdae41c7a --- /dev/null +++ b/app/helpers/interruption_screen_helper.rb @@ -0,0 +1,41 @@ +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 + + def display_title_text(title_text, case_log) + if title_text["arguments"] + translation_params = {} + title_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 + translation = I18n.t(title_text["translation"], **translation_params) + else + translation = I18n.t(title_text) + end + translation.to_s + 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..ff2a962c4 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,34 @@ 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 + + define_method("plural_gender_for_person_#{person_num}") do + plural_gender_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 + + def plural_gender_for_person(person_num) + gender = public_send("sex#{person_num}".to_sym) + return unless gender + + if %w[M X].include?(gender) + "men and non-binary people" + elsif gender == "F" + "women" + end + end + private PIO = Postcodes::IO.new diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index b5397a4f9..1ff8f3ed1 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -45,7 +45,6 @@ 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_relationship_matches_economic_status(record, n) end validate_partner_count(record) @@ -146,10 +145,6 @@ 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 < 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,24 +179,6 @@ 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_partner_count(record) partner_count = (2..8).count { |n| tenant_is_partner?(record["relat#{n}"]) } if partner_count > 1 @@ -209,10 +186,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..406476050 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -38,4 +38,39 @@ 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..c17c7bd84 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: display_title_text(title_text, case_log), 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..90c17de24 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1529,6 +1529,86 @@ } } }, + "lead_tenant_under_retirement_value_check": { + "depends_on": [{ "person_1_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_1", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_1", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_1", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_1", + "label": false, + "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 person isn’t retired?", + "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 +1834,86 @@ } ] }, + "person_2_under_retirement_value_check": { + "depends_on": [{ "person_2_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_2", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_2", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_2", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_2", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -1976,6 +2136,86 @@ } ] }, + "person_3_under_retirement_value_check": { + "depends_on": [{ "person_3_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_3", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_3", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_3", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_3", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -2195,6 +2435,86 @@ } ] }, + "person_4_under_retirement_value_check": { + "depends_on": [{ "person_4_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_4", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_4", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_4", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_4", + "label": false, + "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 person isn’t retired?", + "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 +2731,86 @@ } ] }, + "person_5_under_retirement_value_check": { + "depends_on": [{ "person_5_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_5", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_5", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_5", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_5", + "label": false, + "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 person isn’t retired?", + "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 +3024,86 @@ } ] }, + "person_6_under_retirement_value_check": { + "depends_on": [{ "person_6_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_6", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_6", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_6", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_6", + "label": false, + "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 person isn’t retired?", + "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 +3314,86 @@ } ] }, + "person_7_under_retirement_value_check": { + "depends_on": [{ "person_7_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_7", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_7", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_7", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_7", + "label": false, + "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 person isn’t retired?", + "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 +3600,86 @@ "age8": null } ] + }, + "person_8_under_retirement_value_check": { + "depends_on": [{ "person_8_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_8", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_8", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_8", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_8", + "label": false, + "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 person isn’t retired?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } } } }, @@ -4634,10 +5274,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": { @@ -4647,10 +5295,10 @@ "type": "interruption_screen", "answer_options": { "0": { - "value":"Yes" + "value": "Yes" }, "1": { - "value":"No" + "value": "No" } } } @@ -5628,7 +6276,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": { @@ -5638,10 +6302,10 @@ "type": "interruption_screen", "answer_options": { "0": { - "value":"Yes" + "value": "Yes" }, "1": { - "value":"No" + "value": "No" } } } @@ -5651,7 +6315,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": { @@ -5661,10 +6341,10 @@ "type": "interruption_screen", "answer_options": { "0": { - "value":"Yes" + "value": "Yes" }, "1": { - "value":"No" + "value": "No" } } } diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index d73db181f..4c86c4182 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -1285,7 +1285,7 @@ "value": "Black, African, Caribbean or Black British" }, "4": { - "value": "Other ethnic group" + "value": "Arab or other ethnic group" }, "divider": { "value": true @@ -1523,6 +1523,86 @@ } } }, + "lead_tenant_under_retirement_value_check": { + "depends_on": [{ "person_1_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_1", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_1", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_1", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_1", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -1755,6 +1835,86 @@ } ] }, + "person_2_under_retirement_value_check": { + "depends_on": [{ "person_2_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_2", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_2", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_2", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_2", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -1984,6 +2144,86 @@ } ] }, + "person_3_under_retirement_value_check": { + "depends_on": [{ "person_3_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_3", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_3", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_3", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_3", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -2210,6 +2450,86 @@ } ] }, + "person_4_under_retirement_value_check": { + "depends_on": [{ "person_4_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_4", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_4", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_4", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_4", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -2433,6 +2753,86 @@ } ] }, + "person_5_under_retirement_value_check": { + "depends_on": [{ "person_5_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_5", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_5", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_5", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_5", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -2653,6 +3053,86 @@ } ] }, + "person_6_under_retirement_value_check": { + "depends_on": [{ "person_6_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_6", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_6", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_6", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_6", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -2870,6 +3350,86 @@ } ] }, + "person_7_under_retirement_value_check": { + "depends_on": [{ "person_7_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_7", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_7", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_7", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_7", + "label": false, + "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 person isn’t retired?", + "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": "", @@ -3083,6 +3643,86 @@ "age8": null } ] + }, + "person_8_under_retirement_value_check": { + "depends_on": [{ "person_8_retired_under_soft_min_age?": true }], + "title_text": { + "translation": "soft_validations.retirement.min.title", + "arguments": [{ + "key": "retirement_age_for_person_8", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.min.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_8", + "label": false, + "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 person is retired?", + "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": { + "translation": "soft_validations.retirement.max.title", + "arguments": [{ + "key": "retirement_age_for_person_8", + "label": false, + "i18n_template": "age" + }] + }, + "informative_text": { + "translation": "soft_validations.retirement.max.hint_text", + "arguments": [{ + "key": "plural_gender_for_person_8", + "label": false, + "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 person isn’t retired?", + "type": "interruption_screen", + "answer_options": { + "0": { + "value":"Yes" + }, + "1": { + "value":"No" + } + } + } + } } } }, @@ -4644,18 +5284,19 @@ } }, "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", + "depends_on": [{ "net_income_soft_validation_triggered?": true }], + "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": { @@ -5640,18 +6281,26 @@ ] }, "min_rent_value_check": { - "depends_on": [ - { - "rent_in_soft_min_range?": true - } - ], + "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": { @@ -5671,18 +6320,26 @@ } }, "max_rent_value_check": { - "depends_on": [ - { - "rent_in_soft_max_range?": true - } - ], + "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..9df3a1083 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: "

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}.

" + retirement: + min: + title: "You told us this person is under %{age} and retired" + hint_text: "The minimum expected retirement age for %{gender} in England is %{age}." + max: + title: "You told us this person is %{age} or over and not retired" + hint_text: "The minimum expected retirement age for %{gender} in England is %{age}." + devise: two_factor_authentication: success: "Two-factor authentication successful" @@ -253,3 +262,6 @@ en: test: one_argument: "This is based on the tenant’s work situation: %{ecstat1}" + title_text: + no_argument: "Some test text" + one_argument: "You said this: %{ecstat1}" 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/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index 2965046ef..ad889e241 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -131,7 +131,7 @@ RSpec.describe "validations" do click_button("Save and continue") expect(page).to have_current_path("/logs/#{case_log.id}/net-income-value-check") expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation") - expect(page).to have_content("You told us the lead tenant’s working situation is: Full-time – 30 hours or more") + expect(page).to have_content("You told us the lead tenant’s working situation is: full-time – 30 hours or more") expect(page).to have_content("The household income you have entered is £750.00 every week") choose("case-log-net-income-value-check-0-field", allow_label_click: true) click_button("Save and continue") diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index 8a3a15432..f9b1d3d71 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -166,6 +166,7 @@ 0 + 1 diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index c2582b6e8..2bf51746c 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -600,10 +600,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": { @@ -613,10 +621,10 @@ "type": "interruption_screen", "answer_options": { "0": { - "value":"Yes" + "value": "Yes" }, "1": { - "value":"No" + "value": "No" } } } diff --git a/spec/helpers/interruption_screen_helper_spec.rb b/spec/helpers/interruption_screen_helper_spec.rb new file mode 100644 index 000000000..fb1882666 --- /dev/null +++ b/spec/helpers/interruption_screen_helper_spec.rb @@ -0,0 +1,126 @@ +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(I18n.t("soft_validations.net_income.hint_text", ecstat1: case_log.form.get_question("ecstat1", case_log).answer_label(case_log).downcase, earnings: case_log.form.get_question("earnings", case_log).answer_label(case_log))) + 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(I18n.t("test.one_argument", ecstat1: case_log.form.get_question("ecstat1", case_log).answer_label(case_log).downcase)) + 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(I18n.t("test.one_argument", ecstat1: case_log.form.get_question("ecstat1", case_log).answer_label(case_log).downcase)) + 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 + + describe "display_title_text" do + context "when title text has no arguments" do + it "returns the correct title text" do + title_text = "test.title_text.no_argument" + expect(display_title_text(title_text, case_log)) + .to eq(I18n.t("test.title_text.no_argument")) + end + end + + context "when title text has arguments" do + it "returns the correct title text" do + title_text = { + "translation" => "test.title_text.one_argument", + "arguments" => [ + { + "key" => "ecstat1", + "label" => true, + "i18n_template" => "ecstat1", + }, + ], + } + expect(display_title_text(title_text, case_log)) + .to eq(I18n.t("test.title_text.one_argument", ecstat1: case_log.form.get_question("ecstat1", case_log).answer_label(case_log).downcase)) + 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 diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 1b4c4c978..4a8bc8677 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1922,4 +1922,38 @@ RSpec.describe CaseLog do end end end + + describe "#retirement_age_for_person" do + context "when a person gender is Male" do + let(:case_log) { FactoryBot.build(:case_log, sex1: "M") } + + it "returns the expected retirement age" do + expect(case_log.retirement_age_for_person_1).to eq(67) + end + end + + context "when a person gender is Female" do + let(:case_log) { FactoryBot.build(:case_log, sex2: "F") } + + it "returns the expected retirement age" do + expect(case_log.retirement_age_for_person_2).to eq(60) + end + end + + context "when a person gender is Non-Binary" do + let(:case_log) { FactoryBot.build(:case_log, sex3: "X") } + + it "returns the expected retirement age" do + expect(case_log.retirement_age_for_person_3).to eq(67) + end + end + + context "when the person gender is not set" do + let(:case_log) { FactoryBot.build(:case_log) } + + it "returns nil" do + expect(case_log.retirement_age_for_person_3).to be_nil + end + end + end end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index d4cdf77c3..617c45bb0 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -410,16 +410,6 @@ RSpec.describe Validations::HouseholdValidations do end context "when the household contains a person over 70" do - it "validates that person must be retired" do - record.age2 = 71 - record.ecstat2 = 1 - household_validator.validate_household_number_of_other_members(record) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.household.ecstat.retired_over_70", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.household.age.retired_over_70", person_num: 2)) - end - it "expects that person under 70 does not need to be retired" do record.age2 = 50 record.ecstat2 = 1 @@ -438,19 +428,6 @@ RSpec.describe Validations::HouseholdValidations do end context "when the household contains a retired male" do - it "validates that person must be over 65" do - record.age2 = 64 - record.sex2 = "M" - record.ecstat2 = 5 - household_validator.validate_household_number_of_other_members(record) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.household.age.retired_male")) - expect(record.errors["sex2"]) - .to include(match I18n.t("validations.household.gender.retired_male")) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.household.ecstat.retired_male")) - end - it "expects that person is over 65" do record.age2 = 66 record.sex2 = "M" @@ -484,19 +461,6 @@ RSpec.describe Validations::HouseholdValidations do end context "when the household contains a retired female" do - it "validates that person must be over 60" do - record.age2 = 59 - record.sex2 = "F" - record.ecstat2 = 5 - household_validator.validate_household_number_of_other_members(record) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.household.age.retired_female")) - expect(record.errors["sex2"]) - .to include(match I18n.t("validations.household.gender.retired_female")) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.household.ecstat.retired_female")) - end - it "expects that person is over 60" do record.age2 = 61 record.sex2 = "F"