diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 2b8e40e91..c3323ce2b 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -16,7 +16,7 @@ class CaseLogValidator < ActiveModel::Validator end class CaseLog < ApplicationRecord - # include Validations::SoftValidations + include Validations::SoftValidations ALLOWED_INCOME_RANGES = { 1 => OpenStruct.new(soft_min: 143, soft_max: 730, hard_min: 90, hard_max: 1230), 0 => OpenStruct.new(soft_min: 67, soft_max: 620, hard_min: 50, hard_max: 950), @@ -125,7 +125,7 @@ class CaseLog < ApplicationRecord end def net_income_soft_validation_triggered? - true + net_income_in_soft_min_range? || net_income_in_soft_max_range? end def given_reasonable_preference? diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index db6041acb..a862bbe97 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -25,6 +25,18 @@ module Validations::SoftValidations public_send(soft_errors.keys.first) == 1 if soft_errors.present? end + def net_income_in_soft_max_range? + return unless weekly_net_income && ecstat1 + + weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max) + end + + def net_income_in_soft_min_range? + return unless weekly_net_income && ecstat1 + + weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min) + end + private def net_income_validations @@ -44,16 +56,4 @@ private end net_income_errors end - - def net_income_in_soft_max_range? - return unless weekly_net_income && ecstat1 - - weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max) - end - - def net_income_in_soft_min_range? - return unless weekly_net_income && ecstat1 - - weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min) - end end diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 8808cc8db..ae093cd24 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -72,7 +72,7 @@ RSpec.describe "Form Check Answers Page" do # This way only the links in the table will get picked up it "has an answer link for questions missing an answer" do visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers") - assert_selector "a", text: /Answer (?!the missing questions)/, count: 4 + assert_selector "a", text: /Answer (?!the missing questions)/, count: 5 assert_selector "a", text: "Change", count: 0 expect(page).to have_link("Answer", href: "/logs/#{empty_case_log.id}/person-1-age") end @@ -80,7 +80,7 @@ RSpec.describe "Form Check Answers Page" do it "has a change link for answered questions" do fill_in_number_question(empty_case_log.id, "age1", 28, "person-1-age") visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers") - assert_selector "a", text: /Answer (?!the missing questions)/, count: 3 + assert_selector "a", text: /Answer (?!the missing questions)/, count: 4 assert_selector "a", text: "Change", count: 1 expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/person-1-age") end diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index 829532831..28358e949 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -38,7 +38,7 @@ RSpec.describe "Form Page Routing" do visit("/logs/#{id}/person-1-gender") choose("case-log-sex1-f-field", allow_label_click: true) click_button("Save and continue") - expect(page).to have_current_path("/logs/#{id}/household-number-of-other-members") + expect(page).to have_current_path("/logs/#{id}/person-1-working-situation") visit("/logs/#{id}/conditional-question") choose("case-log-preg-occ-1-field", allow_label_click: true) click_button("Save and continue") diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 9ffcc6062..016019b0c 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -42,38 +42,6 @@ RSpec.describe CaseLog do .to include(CaseLogValidator) end end - - context "when soft validations exist" do - context "with an income in upper soft range" do - let(:case_log) do - FactoryBot.create(:case_log, - ecstat1: 1, - earnings: 750, - incfreq: 0) - end - - it "updates soft errors" do - expect(case_log.has_no_unresolved_soft_errors?).to be false - expect(case_log.soft_errors["net_income_value_check"].message) - .to match(I18n.t("soft_validations.net_income.in_soft_max_range.message")) - end - end - - context "with an income in lower soft validation range" do - let(:case_log) do - FactoryBot.create(:case_log, - ecstat1: 1, - earnings: 120, - incfreq: 0) - end - - it "updates soft errors" do - expect(case_log.has_no_unresolved_soft_errors?).to be false - expect(case_log.soft_errors["net_income_value_check"].message) - .to match(I18n.t("soft_validations.net_income.in_soft_min_range.message")) - end - end - end end describe "#update" do diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index 0f6b269d6..9d0620b8d 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -25,12 +25,12 @@ RSpec.describe Form::Subsection, type: :model do end it "has pages" do - expected_pages = %w[tenant_code person_1_age person_1_gender household_number_of_other_members propcode] + expected_pages = %w[tenant_code person_1_age person_1_gender person_1_working_situation household_number_of_other_members propcode] expect(sub_section.pages.map(&:id)).to eq(expected_pages) end it "has questions" do - expected_questions = %w[tenant_code age1 sex1 other_hhmemb relat2 age2 sex2 ecstat2 propcode] + expected_questions = %w[tenant_code age1 sex1 ecstat1 other_hhmemb relat2 age2 sex2 ecstat2 propcode] expect(sub_section.questions.map(&:id)).to eq(expected_questions) end @@ -58,9 +58,9 @@ RSpec.describe Form::Subsection, type: :model do end it "has question helpers for the number of applicable questions" do - expected_questions = %w[tenant_code age1 sex1 other_hhmemb propcode] + expected_questions = %w[tenant_code age1 sex1 ecstat1 other_hhmemb propcode] expect(sub_section.applicable_questions(case_log).map(&:id)).to eq(expected_questions) - expect(sub_section.applicable_questions_count(case_log)).to eq(5) + expect(sub_section.applicable_questions_count(case_log)).to eq(6) end it "has question helpers for the number of answered questions" do @@ -79,7 +79,7 @@ RSpec.describe Form::Subsection, type: :model do end it "has a question helpers for the unanswered questions" do - expected_questions = %w[sex1 other_hhmemb propcode] + expected_questions = %w[sex1 ecstat1 other_hhmemb propcode] expect(sub_section.unanswered_questions(case_log).map(&:id)).to eq(expected_questions) end end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 3b60b5fa1..507d2416c 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -17,7 +17,7 @@ RSpec.describe FormHandler do form_handler = described_class.instance form = form_handler.get_form(test_form_name) expect(form).to be_a(Form) - expect(form.pages.count).to eq(30) + expect(form.pages.count).to eq(31) end end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index f8dc3afad..5cb699061 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -89,6 +89,7 @@ RSpec.describe Form, type: :model do case_log.tenant_code = "123" case_log.age1 = 35 case_log.sex1 = "Male" + case_log.ecstat1 = 0 case_log.other_hhmemb = 0 end @@ -131,7 +132,7 @@ RSpec.describe Form, type: :model do describe "invalidated_page_questions" do context "when dependencies are not met" do - let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question dependent_question layear declaration] } + let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question net_income_value_check dependent_question layear declaration] } it "returns an array of question keys whose pages conditions are not met" do expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid) @@ -139,7 +140,7 @@ RSpec.describe Form, type: :model do end context "with two pages having the same question and only one has dependencies met" do - let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question dependent_question layear declaration] } + let(:expected_invalid) { %w[la_known cbl conditional_question_no_second_question net_income_value_check dependent_question layear declaration] } it "returns an array of question keys whose pages conditions are not met" do case_log["preg_occ"] = "No"