Browse Source

fix some failing specs

pull/372/head
MadeTech Dushan 3 years ago committed by baarkerlounger
parent
commit
b231e00e78
  1. 4
      app/models/case_log.rb
  2. 24
      app/models/validations/soft_validations.rb
  3. 4
      spec/features/form/check_answers_page_spec.rb
  4. 2
      spec/features/form/page_routing_spec.rb
  5. 32
      spec/models/case_log_spec.rb
  6. 10
      spec/models/form/subsection_spec.rb
  7. 2
      spec/models/form_handler_spec.rb
  8. 5
      spec/models/form_spec.rb

4
app/models/case_log.rb

@ -16,7 +16,7 @@ class CaseLogValidator < ActiveModel::Validator
end end
class CaseLog < ApplicationRecord class CaseLog < ApplicationRecord
# include Validations::SoftValidations include Validations::SoftValidations
ALLOWED_INCOME_RANGES = { ALLOWED_INCOME_RANGES = {
1 => OpenStruct.new(soft_min: 143, soft_max: 730, hard_min: 90, hard_max: 1230), 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), 0 => OpenStruct.new(soft_min: 67, soft_max: 620, hard_min: 50, hard_max: 950),
@ -125,7 +125,7 @@ class CaseLog < ApplicationRecord
end end
def net_income_soft_validation_triggered? def net_income_soft_validation_triggered?
true net_income_in_soft_min_range? || net_income_in_soft_max_range?
end end
def given_reasonable_preference? def given_reasonable_preference?

24
app/models/validations/soft_validations.rb

@ -25,6 +25,18 @@ module Validations::SoftValidations
public_send(soft_errors.keys.first) == 1 if soft_errors.present? public_send(soft_errors.keys.first) == 1 if soft_errors.present?
end 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 private
def net_income_validations def net_income_validations
@ -44,16 +56,4 @@ private
end end
net_income_errors net_income_errors
end 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 end

4
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 # This way only the links in the table will get picked up
it "has an answer link for questions missing an answer" do it "has an answer link for questions missing an answer" do
visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers") 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 assert_selector "a", text: "Change", count: 0
expect(page).to have_link("Answer", href: "/logs/#{empty_case_log.id}/person-1-age") expect(page).to have_link("Answer", href: "/logs/#{empty_case_log.id}/person-1-age")
end end
@ -80,7 +80,7 @@ RSpec.describe "Form Check Answers Page" do
it "has a change link for answered questions" do it "has a change link for answered questions" do
fill_in_number_question(empty_case_log.id, "age1", 28, "person-1-age") fill_in_number_question(empty_case_log.id, "age1", 28, "person-1-age")
visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers") 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 assert_selector "a", text: "Change", count: 1
expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/person-1-age") expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/person-1-age")
end end

2
spec/features/form/page_routing_spec.rb

@ -38,7 +38,7 @@ RSpec.describe "Form Page Routing" do
visit("/logs/#{id}/person-1-gender") visit("/logs/#{id}/person-1-gender")
choose("case-log-sex1-f-field", allow_label_click: true) choose("case-log-sex1-f-field", allow_label_click: true)
click_button("Save and continue") 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") visit("/logs/#{id}/conditional-question")
choose("case-log-preg-occ-1-field", allow_label_click: true) choose("case-log-preg-occ-1-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")

32
spec/models/case_log_spec.rb

@ -42,38 +42,6 @@ RSpec.describe CaseLog do
.to include(CaseLogValidator) .to include(CaseLogValidator)
end end
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 end
describe "#update" do describe "#update" do

10
spec/models/form/subsection_spec.rb

@ -25,12 +25,12 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has pages" do 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) expect(sub_section.pages.map(&:id)).to eq(expected_pages)
end end
it "has questions" do 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) expect(sub_section.questions.map(&:id)).to eq(expected_questions)
end end
@ -58,9 +58,9 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has question helpers for the number of applicable questions" do 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(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 end
it "has question helpers for the number of answered questions" do it "has question helpers for the number of answered questions" do
@ -79,7 +79,7 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has a question helpers for the unanswered questions" do 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) expect(sub_section.unanswered_questions(case_log).map(&:id)).to eq(expected_questions)
end end
end end

2
spec/models/form_handler_spec.rb

@ -17,7 +17,7 @@ RSpec.describe FormHandler do
form_handler = described_class.instance form_handler = described_class.instance
form = form_handler.get_form(test_form_name) form = form_handler.get_form(test_form_name)
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(30) expect(form.pages.count).to eq(31)
end end
end end

5
spec/models/form_spec.rb

@ -89,6 +89,7 @@ RSpec.describe Form, type: :model do
case_log.tenant_code = "123" case_log.tenant_code = "123"
case_log.age1 = 35 case_log.age1 = 35
case_log.sex1 = "Male" case_log.sex1 = "Male"
case_log.ecstat1 = 0
case_log.other_hhmemb = 0 case_log.other_hhmemb = 0
end end
@ -131,7 +132,7 @@ RSpec.describe Form, type: :model do
describe "invalidated_page_questions" do describe "invalidated_page_questions" do
context "when dependencies are not met" 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 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) 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 end
context "with two pages having the same question and only one has dependencies met" do 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 it "returns an array of question keys whose pages conditions are not met" do
case_log["preg_occ"] = "No" case_log["preg_occ"] = "No"

Loading…
Cancel
Save