Browse Source

Cldc 1217 retirement soft validation (#570)

* Interruption screen refactor

* Add test for retirement_age_for_person

Co-authored-by: Stéphane Meny <smeny@users.noreply.github.com>

* 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 <smeny@users.noreply.github.com>
Co-authored-by: Dushan Despotovic <dushan@madetech.com>
pull/619/head
Ted-U 3 years ago committed by baarkerlounger
parent
commit
970c9afcf7
  1. 41
      app/helpers/interruption_screen_helper.rb
  2. 13
      app/helpers/interuption_screen_helper.rb
  3. 29
      app/models/case_log.rb
  4. 27
      app/models/validations/household_validations.rb
  5. 35
      app/models/validations/soft_validations.rb
  6. 4
      app/views/form/_interruption_screen_question.html.erb
  7. 688
      config/forms/2021_2022.json
  8. 715
      config/forms/2022_2023.json
  9. 12
      config/locales/en.yml
  10. 5
      db/migrate/20220509110842_add_retirement_value_check.rb
  11. 1
      db/schema.rb
  12. 2
      spec/features/form/validations_spec.rb
  13. 1
      spec/fixtures/exports/case_logs.xml
  14. 12
      spec/fixtures/forms/2021_2022.json
  15. 126
      spec/helpers/interruption_screen_helper_spec.rb
  16. 65
      spec/helpers/interuption_screen_helper_spec.rb
  17. 34
      spec/models/case_log_spec.rb
  18. 36
      spec/models/validations/household_validations_spec.rb

41
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

13
app/helpers/interuption_screen_helper.rb

@ -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

29
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

27
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

35
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

4
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) %>
<p class="govuk-panel__body"><%= display_informative_text(informative_text, case_log) %></p>
<%= f.govuk_radio_buttons_fieldset question.id.to_sym,
legend: { text: question.header },
hint: { text: question.hint_text&.html_safe } do %>

688
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": {
@ -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": {
@ -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": {

715
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": {

12
config/locales/en.yml

@ -230,6 +230,7 @@ en:
soft_validations:
net_income:
title_text: "Net income is outside the expected range based on the lead tenant’s working situation"
hint_text: "<p>You told us the lead tenant’s working situation is: <strong>%{ecstat1}</strong>.</p><p>The household income you have entered is <strong>%{earnings}</strong>.</p>"
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: "<h1 class=\"govuk-heading-l app-panel--interruption\">You told us the rent is %{brent}</h1><p>The minimum rent for this type of property in %{la} is £%{soft_min_for_period}.</p>"
max:
hint_text: "<h1 class=\"govuk-heading-l app-panel--interruption\">You told us the rent is %{brent}</h1><p>The maximum rent for this type of property in %{la} is £%{soft_max_for_period}.</p>"
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}"

5
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

1
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

2
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")

1
spec/fixtures/exports/case_logs.xml vendored

@ -166,6 +166,7 @@
<illness_type_0/>
<tshortfall_known>0</tshortfall_known>
<shelteredaccom/>
<retirement_value_check/>
<providertype>1</providertype>
</form>
</forms>

12
spec/fixtures/forms/2021_2022.json vendored

@ -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": {

126
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

65
spec/helpers/interuption_screen_helper_spec.rb

@ -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("<p>You told us the lead tenant’s working situation is: <strong>Full-time – 30 hours or more</strong>.</p><p>The household income you have entered is <strong>£750.00 every week</strong>.</p>")
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

34
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

36
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"

Loading…
Cancel
Save