Browse Source

Update validation: min retirement

pull/1584/head
Kat 3 years ago
parent
commit
40be295112
  1. 18
      app/models/form/lettings/pages/lead_tenant_under_retirement_value_check.rb
  2. 22
      app/models/form/lettings/pages/person_under_retirement_value_check.rb
  3. 22
      app/models/form/sales/pages/retirement_value_check.rb
  4. 6
      app/models/validations/soft_validations.rb
  5. 144
      config/forms/2022_2023.json
  6. 2
      config/locales/en.yml
  7. 40
      spec/models/form/lettings/pages/person_under_retirement_value_check_spec.rb
  8. 132
      spec/models/form/sales/pages/retirement_value_check_spec.rb
  9. 44
      spec/models/validations/soft_validations_spec.rb

18
app/models/form/lettings/pages/lead_tenant_under_retirement_value_check.rb

@ -7,23 +7,13 @@ class Form::Lettings::Pages::LeadTenantUnderRetirementValueCheck < ::Form::Page
"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,
"key" => "age1",
"label" => true,
"i18n_template" => "age",
},
],
}
@informative_text = {}
end
def questions
@ -31,6 +21,6 @@ class Form::Lettings::Pages::LeadTenantUnderRetirementValueCheck < ::Form::Page
end
def interruption_screen_question_ids
%w[ecstat1 sex1 age1]
%w[ecstat1 age1]
end
end

22
app/models/form/lettings/pages/person_under_retirement_value_check.rb

@ -7,27 +7,13 @@ class Form::Lettings::Pages::PersonUnderRetirementValueCheck < ::Form::Page
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_#{person_index}",
"label" => false,
"i18n_template" => "age",
},
],
}
@informative_text = {
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_#{person_index}",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_#{person_index}",
"label" => false,
"key" => "age#{person_index}",
"label" => true,
"i18n_template" => "age",
},
],
}
@informative_text = {}
@person_index = person_index
end
@ -36,6 +22,6 @@ class Form::Lettings::Pages::PersonUnderRetirementValueCheck < ::Form::Page
end
def interruption_screen_question_ids
["ecstat#{@person_index}", "sex#{@person_index}", "age#{@person_index}"]
["ecstat#{@person_index}", "age#{@person_index}"]
end
end

22
app/models/form/sales/pages/retirement_value_check.rb

@ -11,27 +11,13 @@ class Form::Sales::Pages::RetirementValueCheck < Form::Sales::Pages::Person
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_#{person_index}",
"label" => false,
"i18n_template" => "age",
},
],
}
@informative_text = {
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_#{person_index}",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_#{person_index}",
"label" => false,
"key" => "age#{person_index}",
"label" => true,
"i18n_template" => "age",
},
],
}
@informative_text = {}
end
def questions
@ -41,6 +27,6 @@ class Form::Sales::Pages::RetirementValueCheck < Form::Sales::Pages::Person
end
def interruption_screen_question_ids
["age#{@person_index}", "ecstat#{@person_index}", "sex#{@person_index}"]
["age#{@person_index}", "ecstat#{@person_index}"]
end
end

6
app/models/validations/soft_validations.rb

@ -124,11 +124,9 @@ private
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
return unless age && economic_status
%w[M X].include?(gender) && tenant_is_retired?(economic_status) && age < retirement_age_for_person(person_num) ||
gender == "F" && tenant_is_retired?(economic_status) && age < 60
tenant_is_retired?(economic_status) && age < 60
end
def not_retired_over_soft_max_age?(person_num)

144
config/forms/2022_2023.json

@ -1859,21 +1859,7 @@
}
]
},
"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"
}
]
},
"informative_text": {},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement confirmation",
@ -1900,7 +1886,7 @@
}
}
},
"interruption_screen_question_ids": ["ecstat1", "sex1", "age1"]
"interruption_screen_question_ids": ["ecstat1", "age1"]
},
"lead_tenant_over_retirement_value_check": {
"depends_on": [
@ -2403,21 +2389,7 @@
}
]
},
"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"
}
]
},
"informative_text": {},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement confirmation",
@ -2444,7 +2416,7 @@
}
}
},
"interruption_screen_question_ids": ["ecstat2", "sex2", "age2"]
"interruption_screen_question_ids": ["ecstat2", "age2"]
},
"person_2_over_retirement_value_check": {
"depends_on": [
@ -2944,21 +2916,7 @@
}
]
},
"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"
}
]
},
"informative_text": {},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement confirmation",
@ -2985,7 +2943,7 @@
}
}
},
"interruption_screen_question_ids": ["ecstat3", "sex3", "age3"]
"interruption_screen_question_ids": ["ecstat3", "age3"]
},
"person_3_over_retirement_value_check": {
"depends_on": [
@ -3482,21 +3440,7 @@
}
]
},
"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"
}
]
},
"informative_text": {},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement confirmation",
@ -3523,7 +3467,7 @@
}
}
},
"interruption_screen_question_ids": ["ecstat4", "sex4", "age4"]
"interruption_screen_question_ids": ["ecstat4", "age4"]
},
"person_4_over_retirement_value_check": {
"depends_on": [
@ -4017,21 +3961,7 @@
}
]
},
"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"
}
]
},
"informative_text": {},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement confirmation",
@ -4058,7 +3988,7 @@
}
}
},
"interruption_screen_question_ids": ["ecstat5", "sex5", "age5"]
"interruption_screen_question_ids": ["ecstat5", "age5"]
},
"person_5_over_retirement_value_check": {
"depends_on": [
@ -4549,21 +4479,7 @@
}
]
},
"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"
}
]
},
"informative_text": {},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement confirmation",
@ -4590,7 +4506,7 @@
}
}
},
"interruption_screen_question_ids": ["ecstat6", "sex6", "age6"]
"interruption_screen_question_ids": ["ecstat6", "age6"]
},
"person_6_over_retirement_value_check": {
"depends_on": [
@ -5078,21 +4994,7 @@
}
]
},
"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"
}
]
},
"informative_text": {},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement confirmation",
@ -5119,7 +5021,7 @@
}
}
},
"interruption_screen_question_ids": ["ecstat7", "sex7", "age7"]
"interruption_screen_question_ids": ["ecstat7", "age7"]
},
"person_7_over_retirement_value_check": {
"depends_on": [
@ -5604,21 +5506,7 @@
}
]
},
"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"
}
]
},
"informative_text": {},
"questions": {
"retirement_value_check": {
"check_answer_label": "Retirement confirmation",
@ -5645,7 +5533,7 @@
}
}
},
"interruption_screen_question_ids": ["ecstat8", "sex8", "age8"]
"interruption_screen_question_ids": ["ecstat8", "age8"]
},
"person_8_over_retirement_value_check": {
"depends_on": [

2
config/locales/en.yml

@ -537,7 +537,7 @@ en:
hint_text: "This is %{higher_or_lower} than we would expect"
retirement:
min:
title: "You told us this person is under %{age} and retired"
title: "You told us this person is aged %{age} years 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"

40
spec/models/form/lettings/pages/person_under_retirement_value_check_spec.rb

@ -39,8 +39,8 @@ RSpec.describe Form::Lettings::Pages::PersonUnderRetirementValueCheck, type: :mo
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_2",
"label" => false,
"key" => "age2",
"label" => true,
"i18n_template" => "age",
},
],
@ -48,21 +48,7 @@ RSpec.describe Form::Lettings::Pages::PersonUnderRetirementValueCheck, type: :mo
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({
"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",
},
],
})
expect(page.informative_text).to eq({})
end
end
@ -84,8 +70,8 @@ RSpec.describe Form::Lettings::Pages::PersonUnderRetirementValueCheck, type: :mo
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_3",
"label" => false,
"key" => "age3",
"label" => true,
"i18n_template" => "age",
},
],
@ -93,21 +79,7 @@ RSpec.describe Form::Lettings::Pages::PersonUnderRetirementValueCheck, type: :mo
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({
"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",
},
],
})
expect(page.informative_text).to eq({})
end
end
end

132
spec/models/form/sales/pages/retirement_value_check_spec.rb

@ -46,8 +46,8 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_1",
"label" => false,
"key" => "age1",
"label" => true,
"i18n_template" => "age",
},
],
@ -55,25 +55,11 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"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",
},
],
})
expect(page.informative_text).to eq({})
end
it "has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[age1 ecstat1 sex1])
expect(page.interruption_screen_question_ids).to eq(%w[age1 ecstat1])
end
end
@ -98,8 +84,8 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_2",
"label" => false,
"key" => "age2",
"label" => true,
"i18n_template" => "age",
},
],
@ -107,25 +93,11 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"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",
},
],
})
expect(page.informative_text).to eq({})
end
it "has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[age2 ecstat2 sex2])
expect(page.interruption_screen_question_ids).to eq(%w[age2 ecstat2])
end
end
@ -150,8 +122,8 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_3",
"label" => false,
"key" => "age3",
"label" => true,
"i18n_template" => "age",
},
],
@ -159,25 +131,11 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"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",
},
],
})
expect(page.informative_text).to eq({})
end
it "has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[age3 ecstat3 sex3])
expect(page.interruption_screen_question_ids).to eq(%w[age3 ecstat3])
end
end
@ -202,8 +160,8 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_4",
"label" => false,
"key" => "age4",
"label" => true,
"i18n_template" => "age",
},
],
@ -211,25 +169,11 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"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",
},
],
})
expect(page.informative_text).to eq({})
end
it "has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[age4 ecstat4 sex4])
expect(page.interruption_screen_question_ids).to eq(%w[age4 ecstat4])
end
end
@ -254,8 +198,8 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_5",
"label" => false,
"key" => "age5",
"label" => true,
"i18n_template" => "age",
},
],
@ -263,25 +207,11 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"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",
},
],
})
expect(page.informative_text).to eq({})
end
it "has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[age5 ecstat5 sex5])
expect(page.interruption_screen_question_ids).to eq(%w[age5 ecstat5])
end
end
@ -306,8 +236,8 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_6",
"label" => false,
"key" => "age6",
"label" => true,
"i18n_template" => "age",
},
],
@ -315,25 +245,11 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"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",
},
],
})
expect(page.informative_text).to eq({})
end
it "has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[age6 ecstat6 sex6])
expect(page.interruption_screen_question_ids).to eq(%w[age6 ecstat6])
end
end
end

44
spec/models/validations/soft_validations_spec.rb

@ -84,25 +84,9 @@ RSpec.describe Validations::SoftValidations do
describe "retirement soft validations" do
context "when the tenant is retired but under the expected retirement age" do
context "when the tenant is female" do
it "shows the interruption screen" do
record.update!(age1: 43, sex1: "F", ecstat1: 5)
expect(record.person_1_retired_under_soft_min_age?).to be true
end
end
context "when the tenant is male" do
it "shows the interruption screen" do
record.update!(age1: 43, sex1: "M", ecstat1: 5)
expect(record.person_1_retired_under_soft_min_age?).to be true
end
end
context "when the tenant is non-binary" do
it "shows the interruption screen" do
record.update!(age1: 43, sex1: "X", ecstat1: 5)
expect(record.person_1_retired_under_soft_min_age?).to be true
end
it "shows the interruption screen" do
record.update!(age1: 43, ecstat1: 5)
expect(record.person_1_retired_under_soft_min_age?).to be true
end
end
@ -130,25 +114,9 @@ RSpec.describe Validations::SoftValidations do
end
context "when the tenant prefers not to say what their economic status is but is under the expected retirement age" do
context "when the tenant is female" do
it "does not show the interruption screen" do
record.update!(age1: 43, sex1: "F", ecstat1: 10)
expect(record.person_1_retired_under_soft_min_age?).to be false
end
end
context "when the tenant is male" do
it "does not show the interruption screen" do
record.update!(age1: 43, sex1: "M", ecstat1: 10)
expect(record.person_1_retired_under_soft_min_age?).to be false
end
end
context "when the tenant is non-binary" do
it "does not show the interruption screen" do
record.update!(age1: 43, sex1: "X", ecstat1: 10)
expect(record.person_1_retired_under_soft_min_age?).to be false
end
it "does not show the interruption screen" do
record.update!(age1: 43, ecstat1: 10)
expect(record.person_1_retired_under_soft_min_age?).to be false
end
end

Loading…
Cancel
Save