From b6032fd3fac3f0c78d6942e3233ac64d67c95025 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Thu, 18 Nov 2021 17:02:10 +0000 Subject: [PATCH] Specs --- app/models/form.rb | 2 +- spec/factories/case_log.rb | 120 +++++++++++++++++++++++++-- spec/fixtures/forms/test_form.json | 11 ++- spec/helpers/tasklist_helper_spec.rb | 1 - spec/models/form_spec.rb | 2 + 5 files changed, 127 insertions(+), 9 deletions(-) diff --git a/app/models/form.rb b/app/models/form.rb index fdebf1aa3..332de94bb 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -124,7 +124,7 @@ class Form return true unless conditions conditions.all? do |subsection, status| - subsection_status(subsection, case_log) == status + subsection_status(subsection, case_log) == status.to_sym end end diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index b1c856c16..f36579443 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -4,15 +4,10 @@ FactoryBot.define do trait :in_progress do status { 1 } tenant_code { "TH356" } - property_postcode { "P0 5ST" } + postcode { "P0 5ST" } previous_postcode { "SW2 6HI" } age1 { "17" } end - trait :completed do - status { 2 } - tenant_code { "BZ737" } - property_postcode { "NW1 7TY" } - end trait :soft_validations_triggered do status { 1 } ecstat1 { "Full-time - 30 hours or more" } @@ -28,6 +23,119 @@ FactoryBot.define do ecstat1 { 2 } other_hhmemb { 0 } end + trait :completed do + status { 2 } + tenant_code { "BZ737" } + postcode { "NW1 7TY" } + age1 { 35 } + sex1 { "F" } + ethnic { 2 } + national { 4 } + prevten { "Private sector tenancy" } + ecstat1 { 2 } + other_hhmemb { 1 } + hhmemb { 2 } + relat2 { "Partner" } + age2 { 32 } + sex2 { "Male" } + ecstat2 { "Not seeking work" } + homeless { "Yes - other homelessness" } + underoccupation_benefitcap { "No" } + leftreg { "No - they left up to 5 years ago" } + reservist { "No" } + illness { "Yes" } + preg_occ { "No" } + accessibility_requirements { "No" } + condition_effects { "dummy" } + tenancy_code { "BZ757" } + startertenancy { "No" } + tenancylength { 5 } + tenancy { "Secure (including flexible)" } + lettype { "Affordable Rent - General Needs" } + landlord { "This landlord" } + previous_postcode { "SE2 6RT" } + rsnvac { "Relet - tenant abandoned property" } + unittype_gn { "House" } + property_building_type { "dummy" } + beds { 3 } + property_void_date { "03/11/2019" } + offered { 2 } + wchair { "Yes" } + earnings { 60 } + incfreq { "Weekly" } + benefits { "Some" } + period { "Fortnightly" } + brent { 200 } + scharge { 50 } + pscharge { 40 } + supcharg { 35 } + tcharge { 325 } + layear { "1 to 2 years" } + lawaitlist { "Less than 1 year" } + property_postcode { "NW1 5TY" } + reasonpref { "Yes" } + reasonable_preference_reason { "dummy" } + cbl { "Yes" } + chr { "Yes" } + cap { "No" } + other_reason_for_leaving_last_settled_home { nil } + housingneeds_a { "Yes" } + housingneeds_b { "No" } + housingneeds_c { "No" } + housingneeds_f { "No" } + housingneeds_g { "No" } + housingneeds_h { "No" } + accessibility_requirements_prefer_not_to_say { 0 } + illness_type_1 { "No" } + illness_type_2 { "Yes" } + illness_type_3 { "No" } + illness_type_4 { "No" } + illness_type_8 { "No" } + illness_type_5 { "No" } + illness_type_6 { "No" } + illness_type_7 { "No" } + illness_type_9 { "No" } + illness_type_10 { "No" } + rp_homeless { "Yes" } + rp_insan_unsat { "No" } + rp_medwel { "No" } + rp_hardship { "No" } + rp_dontknow { "No" } + discarded_at { nil } + tenancyother { nil } + override_net_income_validation { nil } + net_income_known { "Yes" } + gdpr_acceptance { "Yes" } + gdpr_declined { "No" } + property_owner_organisation { "Test" } + property_manager_organisation { "Test" } + sale_or_letting { "Letting" } + tenant_same_property_renewal { 1 } + rent_type { 1 } + intermediate_rent_product_name { 2 } + needs_type { 1 } + purchaser_code { 798794 } + reason { "Permanently decanted from another property owned by this landlord" } + propcode { "123" } + majorrepairs { "Yes" } + la { "Barnet" } + prevloc { "Ashford" } + hb { 1 } + hbrentshortfall { "Yes" } + tshortfall { 12 } + postcod2 { "w3" } + ppostc1 { "w3" } + ppostc2 { "w3" } + property_relet { "No" } + mrcdate { Time.zone.now } + mrcday { 5 } + mrcmonth { 5 } + mrcyear { 2020 } + incref { 554355 } + sale_completion_date { nil } + startdate { nil } + armedforces { 1 } + end created_at { Time.zone.now } updated_at { Time.zone.now } end diff --git a/spec/fixtures/forms/test_form.json b/spec/fixtures/forms/test_form.json index 4b2fd6c65..1b05c4121 100644 --- a/spec/fixtures/forms/test_form.json +++ b/spec/fixtures/forms/test_form.json @@ -365,7 +365,7 @@ "pages": { "rent": { "questions": { - "rent_frequency": { + "period": { "check_answer_label": "Rent Period", "header": "Which period are rent and other charges due?", "type": "radio", @@ -529,6 +529,15 @@ "subsections": { "declaration": { "label": "Declaration", + "depends_on": { + "household_characteristics": "completed", + "household_needs": "completed", + "tenancy_information": "completed", + "property_information": "completed", + "income_and_benefits": "completed", + "rent": "completed", + "local_authority": "completed" + }, "pages": { "declaration": { "questions": { diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 1c409fe9d..1e8cafd5f 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -3,7 +3,6 @@ require "rails_helper" RSpec.describe TasklistHelper do let(:empty_case_log) { FactoryBot.build(:case_log) } let(:case_log) { FactoryBot.build(:case_log, :in_progress) } - let(:completed_case_log) { FactoryBot.build(:case_log, :completed) } form_handler = FormHandler.instance let(:form) { form_handler.get_form("test_form") } let(:household_characteristics_questions) { form.questions_for_subsection("household_characteristics") } diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 4833e5c1c..e7b9e7bad 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -4,6 +4,8 @@ RSpec.describe Form, type: :model do form_handler = FormHandler.instance let(:form) { form_handler.get_form("test_form") } let(:case_log) { FactoryBot.build(:case_log, :in_progress) } + let(:completed_case_log) { FactoryBot.build(:case_log, :completed) } + let(:conditional_section_complete_case_log) { FactoryBot.build(:case_log, :conditional_section_complete) } describe ".next_page" do let(:previous_page) { "person_1_age" }