diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index 1c971c4d5..6fdbd9c5a 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -62,7 +62,7 @@ class BulkUpload # managementgroup: row[4], # schemecode: row[5], # firstletting: row[6], - tenant_code: row[7], + tenancycode: row[7], startertenancy: row[8], tenancy: row[9], tenancyother: row[10], diff --git a/app/models/case_log.rb b/app/models/case_log.rb index faf07ca05..00dc9505f 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -18,6 +18,7 @@ end class CaseLog < ApplicationRecord include Validations::SoftValidations + include DerivedVariables::CaseLogVariables has_paper_trail @@ -52,7 +53,7 @@ class CaseLog < ApplicationRecord } scope :filter_by_id, ->(id) { where(id:) } - scope :filter_by_tenant_code, ->(tenant_code) { where("tenant_code ILIKE ?", "%#{tenant_code}%") } + scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") } scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") } scope :filter_by_postcode, ->(postcode_full) { where("postcode_full ILIKE ?", "%#{postcode_full.gsub(/\s+/, '')}%") } scope :search_by, lambda { |param| @@ -63,8 +64,7 @@ class CaseLog < ApplicationRecord } AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze - OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenant_code propcode].freeze - RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze + OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode].freeze RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze @@ -112,10 +112,6 @@ class CaseLog < ApplicationRecord status == "in_progress" end - def supported_housing_schemes_enabled? - FeatureToggle.supported_housing_schemes_enabled? - end - def weekly_net_income return unless earnings && incfreq @@ -201,7 +197,7 @@ class CaseLog < ApplicationRecord def previous_postcode_known? # 1: Yes - previous_postcode_known == 1 + ppcodenk == 1 end def previous_la_known? @@ -266,10 +262,12 @@ class CaseLog < ApplicationRecord def previous_tenancy_was_temporary? # 4: Tied housing or renting with job # 6: Supported housing - # 8: Sheltered accomodation + # 8: Sheltered accomodation (<= 21/22) # 24: Housed by National Asylum Support Service (prev Home Office) # 25: Other - ![4, 6, 8, 24, 25].include?(prevten) + # 34: Specialist retirement housing + # 35: Extra care housing + ![4, 6, 8, 24, 25, 34, 35].include?(prevten) end def armed_forces_regular? @@ -302,11 +300,6 @@ class CaseLog < ApplicationRecord homeless == 11 end - def is_other_homeless? - # 7: Other homeless – not found statutorily homeless but considered homeless by landlord - homeless == 7 - end - def is_not_homeless? # 1: No homeless == 1 @@ -338,6 +331,11 @@ class CaseLog < ApplicationRecord hb == 1 end + def benefits_unknown? + hb == 3 + end + + # Option 8 has been removed starting from 22/23 def receives_housing_benefit_and_universal_credit? # 8: Housing benefit and Universal Credit (without housing element) hb == 8 @@ -353,6 +351,11 @@ class CaseLog < ApplicationRecord hb == 9 end + def tenant_refuses_to_say_benefits? + hb == 10 + end + + # Option 7 has been removed starting from 22/23 def receives_universal_credit_but_no_housing_benefit? # 7: Universal Credit (without housing element) hb == 7 @@ -363,13 +366,12 @@ class CaseLog < ApplicationRecord end def receives_housing_related_benefits? - receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? || - receives_housing_benefit_and_universal_credit? - end - - def benefits_unknown? - # 3: Don’t know - hb == 3 + if collection_start_year <= 2021 + receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? || + receives_housing_benefit_and_universal_credit? + else + receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? + end end def local_housing_referral? @@ -522,64 +524,6 @@ private collection_start_year >= 2022 && !is_fixed_term_tenancy? end - def set_derived_fields! - # TODO: Remove once we support supported housing logs - self.needstype = 1 unless FeatureToggle.supported_housing_schemes_enabled? - if rsnvac.present? - self.newprop = has_first_let_vacancy_reason? ? 1 : 2 - end - self.incref = 1 if net_income_refused? - self.renttype = RENT_TYPE_MAPPING[rent_type] - self.lettype = get_lettype - self.totchild = get_totchild - self.totelder = get_totelder - self.totadult = get_totadult - self.refused = get_refused - self.ethnic = 17 if ethnic_refused? - if %i[brent scharge pscharge supcharg].any? { |f| public_send(f).present? } - self.brent ||= 0 - self.scharge ||= 0 - self.pscharge ||= 0 - self.supcharg ||= 0 - self.tcharge = brent.to_f + scharge.to_f + pscharge.to_f + supcharg.to_f - end - if period.present? - self.wrent = weekly_value(brent) if brent.present? - self.wscharge = weekly_value(scharge) if scharge.present? - self.wpschrge = weekly_value(pscharge) if pscharge.present? - self.wsupchrg = weekly_value(supcharg) if supcharg.present? - self.wtcharge = weekly_value(tcharge) if tcharge.present? - if is_supported_housing? && chcharge.present? - self.wchchrg = weekly_value(chcharge) - end - end - self.has_benefits = get_has_benefits - self.tshortfall_known = 0 if tshortfall - self.wtshortfall = if tshortfall && receives_housing_related_benefits? - weekly_value(tshortfall) - end - self.nocharge = household_charge&.zero? ? 1 : 0 - self.housingneeds = get_housingneeds - if is_renewal? - self.underoccupation_benefitcap = 2 if collection_start_year == 2021 - self.homeless = 2 - self.referral = 0 - self.waityear = 1 - if is_general_needs? - # fixed term - self.prevten = 32 if managing_organisation.provider_type == "PRP" - self.prevten = 30 if managing_organisation.provider_type == "LA" - end - end - (2..8).each do |idx| - if age_under_16?(idx) - self["ecstat#{idx}"] = 9 - elsif public_send("ecstat#{idx}") == 9 && age_known?(idx) - self["ecstat#{idx}"] = nil - end - end - end - def age_under_16?(person_num) public_send("age#{person_num}") && public_send("age#{person_num}") < 16 end @@ -591,7 +535,7 @@ private def process_previous_postcode_changes! self.ppostcode_full = upcase_and_remove_whitespace(ppostcode_full) - process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc") + process_postcode(ppostcode_full, "ppcodenk", "is_previous_la_inferred", "prevloc") end def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key) @@ -619,31 +563,6 @@ private self[postcode_key] = nil end - def get_totelder - ages = [age1, age2, age3, age4, age5, age6, age7, age8] - ages.count { |x| !x.nil? && x >= 60 } - end - - def get_totchild - relationships = [relat2, relat3, relat4, relat5, relat6, relat7, relat8] - relationships.count("C") - end - - def get_totadult - total = !age1.nil? && age1 >= 16 && age1 < 60 ? 1 : 0 - total + (2..8).count do |i| - age = public_send("age#{i}") - relat = public_send("relat#{i}") - !age.nil? && ((age >= 16 && age < 18 && %w[P X].include?(relat)) || age >= 18 && age < 60) - end - end - - def get_refused - return 1 if age_refused? || sex_refused? || relat_refused? || ecstat_refused? - - 0 - end - def get_inferred_la(postcode) # Avoid network calls when postcode is invalid return unless postcode.match(Validations::PropertyValidations::POSTCODE_REGEXP) diff --git a/app/models/derived_variables/case_log_variables.rb b/app/models/derived_variables/case_log_variables.rb new file mode 100644 index 000000000..e63112cb0 --- /dev/null +++ b/app/models/derived_variables/case_log_variables.rb @@ -0,0 +1,172 @@ +module DerivedVariables::CaseLogVariables + RENT_TYPE_MAPPING = { 0 => 1, 1 => 2, 2 => 2, 3 => 3, 4 => 3, 5 => 3 }.freeze + + def supported_housing_schemes_enabled? + FeatureToggle.supported_housing_schemes_enabled? + end + + def set_derived_fields! + # TODO: Remove once we support supported housing logs + self.needstype = 1 unless supported_housing_schemes_enabled? + if rsnvac.present? + self.newprop = has_first_let_vacancy_reason? ? 1 : 2 + end + self.incref = 1 if net_income_refused? + self.renttype = RENT_TYPE_MAPPING[rent_type] + self.lettype = get_lettype + self.totchild = get_totchild + self.totelder = get_totelder + self.totadult = get_totadult + self.refused = get_refused + self.ethnic = 17 if ethnic_refused? + if %i[brent scharge pscharge supcharg].any? { |f| public_send(f).present? } + self.brent ||= 0 + self.scharge ||= 0 + self.pscharge ||= 0 + self.supcharg ||= 0 + self.tcharge = brent.to_f + scharge.to_f + pscharge.to_f + supcharg.to_f + end + if period.present? + self.wrent = weekly_value(brent) if brent.present? + self.wscharge = weekly_value(scharge) if scharge.present? + self.wpschrge = weekly_value(pscharge) if pscharge.present? + self.wsupchrg = weekly_value(supcharg) if supcharg.present? + self.wtcharge = weekly_value(tcharge) if tcharge.present? + if is_supported_housing? && chcharge.present? + self.wchchrg = weekly_value(chcharge) + end + end + self.has_benefits = get_has_benefits + self.tshortfall_known = 0 if tshortfall + self.wtshortfall = if tshortfall && receives_housing_related_benefits? + weekly_value(tshortfall) + end + self.nocharge = household_charge&.zero? ? 1 : 0 + self.housingneeds = get_housingneeds + if is_renewal? + self.underoccupation_benefitcap = 2 if collection_start_year == 2021 + self.homeless = 1 + self.referral = 0 + self.waityear = 2 + if is_general_needs? + # fixed term + self.prevten = 32 if managing_organisation.provider_type == "PRP" + self.prevten = 30 if managing_organisation.provider_type == "LA" + end + end + + child_under_16_constraints! + + self.hhtype = household_type + self.new_old = new_or_existing_tenant + self.vacdays = property_vacant_days + end + +private + + def get_totelder + ages = [age1, age2, age3, age4, age5, age6, age7, age8] + ages.count { |x| !x.nil? && x >= 60 } + end + + def get_totchild + relationships = [relat2, relat3, relat4, relat5, relat6, relat7, relat8] + relationships.count("C") + end + + def get_totadult + total = !age1.nil? && age1 >= 16 && age1 < 60 ? 1 : 0 + total + (2..8).count do |i| + age = public_send("age#{i}") + relat = public_send("relat#{i}") + !age.nil? && ((age >= 16 && age < 18 && %w[P X].include?(relat)) || age >= 18 && age < 60) + end + end + + def get_refused + return 1 if age_refused? || sex_refused? || relat_refused? || ecstat_refused? + + 0 + end + + def child_under_16_constraints! + (2..8).each do |idx| + if age_under_16?(idx) + self["ecstat#{idx}"] = 9 + elsif public_send("ecstat#{idx}") == 9 && age_known?(idx) + self["ecstat#{idx}"] = nil + end + end + end + + def household_type + return unless totelder && totadult && totchild + + if only_one_elder? + 1 + elsif two_adults_including_elders? + 2 + elsif only_one_adult? + 3 + elsif only_two_adults? + 4 + elsif one_adult_with_at_least_one_child? + 5 + elsif two_adults_with_at_least_one_child? + 6 + else + 9 + end + end + + def two_adults_with_at_least_one_child? + totelder.zero? && totadult >= 2 && totchild >= 1 + end + + def one_adult_with_at_least_one_child? + totelder.zero? && totadult == 1 && totchild >= 1 + end + + def only_two_adults? + totelder.zero? && totadult == 2 && totchild.zero? + end + + def only_one_adult? + totelder.zero? && totadult == 1 && totchild.zero? + end + + def two_adults_including_elders? + (totelder + totadult) == 2 && totelder >= 1 + end + + def only_one_elder? + totelder == 1 && totadult.zero? && totchild.zero? + end + + def new_or_existing_tenant + return unless startdate + + referral_within_sector = [1, 10] + previous_social_tenancies = if collection_start_year <= 2021 + [6, 8, 30, 31, 32, 33] + else + [6, 30, 31, 32, 33, 34, 35] + end + + if previous_social_tenancies.include?(prevten) || referral_within_sector.include?(referral) + 2 # Tenant existing in social housing sector + else + 1 # Tenant new to social housing sector + end + end + + def property_vacant_days + return unless startdate + + if mrcdate.present? + (startdate - mrcdate).to_i / 1.day + elsif voiddate.present? + (startdate - voiddate).to_i / 1.day + end + end +end diff --git a/app/models/form.rb b/app/models/form.rb index 701589432..0353fb08c 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -124,7 +124,7 @@ class Form def invalidated_page_questions(case_log) # we're already treating address fields as a special case and reset their values upon saving a case_log - address_questions = %w[postcode_known la previous_postcode_known previous_la_known prevloc postcode_full ppostcode_full] + address_questions = %w[postcode_known la ppcodenk previous_la_known prevloc postcode_full ppostcode_full] invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || [] end diff --git a/app/models/form/question.rb b/app/models/form/question.rb index fac943a6e..e60802b3c 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -237,13 +237,13 @@ private RADIO_YES_VALUE = { renewal: [1], postcode_known: [1], - previous_postcode_known: [1], + ppcodenk: [1], previous_la_known: [1], first_time_property_let_as_social_housing: [1], wchair: [1], majorrepairs: [1], startertenancy: [0], - shelteredaccom: [0, 1], + sheltered: [0, 1], armedforces: [1, 4, 5], leftreg: [0], reservist: [0], @@ -261,13 +261,13 @@ private RADIO_NO_VALUE = { renewal: [0], postcode_known: [0], - previous_postcode_known: [0], + ppcodenk: [0], previous_la_known: [0], first_time_property_let_as_social_housing: [0], wchair: [0], majorrepairs: [0], startertenancy: [1], - shelteredaccom: [2], + sheltered: [2], armedforces: [2], leftreg: [1], reservist: [1], @@ -283,7 +283,7 @@ private }.freeze RADIO_DONT_KNOW_VALUE = { - shelteredaccom: [3], + sheltered: [3], underoccupation_benefitcap: [3], reasonpref: [3], hbrentshortfall: [3], @@ -319,7 +319,7 @@ private ecstat6: [10], ecstat7: [10], ecstat8: [10], - shelteredaccom: [3], + sheltered: [3], armedforces: [3], leftreg: [3], reservist: [2], diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 857ceb45a..5b46e1b4c 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -51,14 +51,25 @@ module Validations::FinancialValidations end def validate_tshortfall(record) - if record.has_hbrentshortfall? && - (record.benefits_unknown? || - record.receives_no_benefits? || - record.receives_universal_credit_but_no_housing_benefit?) + if record.has_hbrentshortfall? && no_known_benefits?(record) record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") end end + def no_known_benefits?(record) + return true unless record.collection_start_year + + if record.collection_start_year <= 2021 + record.benefits_unknown? || + record.receives_no_benefits? || + record.receives_universal_credit_but_no_housing_benefit? + else + record.benefits_unknown? || + record.receives_no_benefits? || + record.tenant_refuses_to_say_benefits? + end + end + def validate_rent_amount(record) if record.brent.present? && record.tshortfall.present? && record.brent < record.tshortfall * 2 record.errors.add :brent, I18n.t("validations.financial.rent.less_than_double_shortfall", tshortfall: record.tshortfall * 2) diff --git a/app/services/exports/case_log_export_constants.rb b/app/services/exports/case_log_export_constants.rb index 4899c76e4..1f8770d29 100644 --- a/app/services/exports/case_log_export_constants.rb +++ b/app/services/exports/case_log_export_constants.rb @@ -36,6 +36,7 @@ module Exports::CaseLogExportConstants "hbrentshortfall", "hcnum", "hhmemb", + "hhtype", "homeless", "housingneeds", "illness", @@ -92,7 +93,7 @@ module Exports::CaseLogExportConstants "scharge", "scheme", "schtype", - "shelteredaccom", + "sheltered", "startdate", "startertenancy", "supcharg", @@ -114,6 +115,7 @@ module Exports::CaseLogExportConstants "unittype_sh", "uploaddate", "username", + "vacdays", "voiddate", "waityear", "wchair", diff --git a/app/services/exports/case_log_export_service.rb b/app/services/exports/case_log_export_service.rb index d2890d455..17f271762 100644 --- a/app/services/exports/case_log_export_service.rb +++ b/app/services/exports/case_log_export_service.rb @@ -179,8 +179,6 @@ module Exports # Mapping which would require a change in our data model attribute_hash["createddate"] = attribute_hash["created_at"] attribute_hash["uploaddate"] = attribute_hash["updated_at"] - attribute_hash["tenancycode"] = attribute_hash["tenant_code"] - attribute_hash["ppcodenk"] = attribute_hash["previous_postcode_known"] attribute_hash["cbl"] = 2 if attribute_hash["cbl"]&.zero? attribute_hash["cap"] = 2 if attribute_hash["cap"]&.zero? diff --git a/app/services/imports/case_logs_field_import_service.rb b/app/services/imports/case_logs_field_import_service.rb index 97d8afbf8..3f26c74cf 100644 --- a/app/services/imports/case_logs_field_import_service.rb +++ b/app/services/imports/case_logs_field_import_service.rb @@ -2,7 +2,7 @@ module Imports class CaseLogsFieldImportService < ImportService def update_field(field, folder) case field - when "tenant_code" + when "tenancycode" import_from(folder, :update_tenant_code) when "major_repairs" import_from(folder, :update_major_repairs) @@ -74,10 +74,10 @@ module Imports if record.present? tenant_code = string_or_nil(xml_doc, "_2bTenCode") - if tenant_code.present? && record.tenant_code.blank? - record.update!(tenant_code:) + if tenant_code.present? && record.tenancycode.blank? + record.update!(tenancycode: tenant_code) else - @logger.info("Case Log #{record.id} has a value for tenant_code, skipping update") + @logger.info("Case Log #{record.id} has a value for tenancycode, skipping update") end else @logger.warn("Could not find record matching legacy ID #{old_id}") diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb index 14975a546..936218838 100644 --- a/app/services/imports/case_logs_import_service.rb +++ b/app/services/imports/case_logs_import_service.rb @@ -61,7 +61,7 @@ module Imports attributes["joint"] = unsafe_string_as_integer(xml_doc, "joint") attributes["startertenancy"] = unsafe_string_as_integer(xml_doc, "_2a") attributes["tenancy"] = unsafe_string_as_integer(xml_doc, "Q2b") - attributes["tenant_code"] = string_or_nil(xml_doc, "_2bTenCode") + attributes["tenancycode"] = string_or_nil(xml_doc, "_2bTenCode") attributes["tenancyother"] = string_or_nil(xml_doc, "Q2ba") attributes["tenancylength"] = safe_string_as_integer(xml_doc, "_2cYears") attributes["needstype"] = needs_type(xml_doc) @@ -111,7 +111,7 @@ module Imports attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q11") attributes["prevloc"] = string_or_nil(xml_doc, "Q12aONS") attributes["ppostcode_full"] = compose_postcode(xml_doc, "PPOSTC1", "PPOSTC2") - attributes["previous_postcode_known"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"]) + attributes["ppcodenk"] = previous_postcode_known(xml_doc, attributes["ppostcode_full"], attributes["prevloc"]) attributes["layear"] = unsafe_string_as_integer(xml_doc, "Q12c") attributes["waityear"] = unsafe_string_as_integer(xml_doc, "Q12d") attributes["homeless"] = unsafe_string_as_integer(xml_doc, "Q13") diff --git a/app/views/case_logs/_log_list.html.erb b/app/views/case_logs/_log_list.html.erb index dfccaabf9..8041f5cc5 100644 --- a/app/views/case_logs/_log_list.html.erb +++ b/app/views/case_logs/_log_list.html.erb @@ -51,7 +51,7 @@ <% end %> <% end %> <% row.cell( - text: log.tenant_code? ? log.tenant_code : "–", + text: log.tenancycode? ? log.tenancycode : "–", classes: "app-!-font-tabular", ) %> <% row.cell( diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 46ed45a4b..d6d4f1403 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -981,7 +981,7 @@ "header": "", "description": "", "questions": { - "shelteredaccom": { + "sheltered": { "check_answer_label": "Is this letting in sheltered accommodation?", "header": "Is this letting in sheltered accommodation?", "hint_text": "", @@ -1161,7 +1161,14 @@ "age1": [0] }, "hidden_in_check_answers": { - "depends_on": [{ "age1_known": 0 }, { "age1_known": 1 }] + "depends_on": [ + { + "age1_known": 0 + }, + { + "age1_known": 1 + } + ] } }, "age1": { @@ -1859,7 +1866,14 @@ "age2": [0] }, "hidden_in_check_answers": { - "depends_on": [{ "age2_known": 0 }, { "age2_known": 1 }] + "depends_on": [ + { + "age2_known": 0 + }, + { + "age2_known": 1 + } + ] } }, "age2": { @@ -2147,7 +2161,10 @@ "depends_on": [ { "details_known_2": 0, - "age2": { "operator": ">", "operand": 15 } + "age2": { + "operator": ">", + "operand": 15 + } }, { "details_known_2": 0, @@ -2340,7 +2357,14 @@ "age3": [0] }, "hidden_in_check_answers": { - "depends_on": [{ "age3_known": 0 }, { "age3_known": 1 }] + "depends_on": [ + { + "age3_known": 0 + }, + { + "age3_known": 1 + } + ] } }, "age3": { @@ -2628,7 +2652,10 @@ "depends_on": [ { "details_known_3": 0, - "age3": { "operator": ">", "operand": 15 } + "age3": { + "operator": ">", + "operand": 15 + } }, { "details_known_3": 0, @@ -2818,7 +2845,14 @@ "age4": [0] }, "hidden_in_check_answers": { - "depends_on": [{ "age4_known": 0 }, { "age4_known": 1 }] + "depends_on": [ + { + "age4_known": 0 + }, + { + "age4_known": 1 + } + ] } }, "age4": { @@ -3106,7 +3140,10 @@ "depends_on": [ { "details_known_4": 0, - "age4": { "operator": ">", "operand": 15 } + "age4": { + "operator": ">", + "operand": 15 + } }, { "details_known_4": 0, @@ -3293,7 +3330,14 @@ "age5": [0] }, "hidden_in_check_answers": { - "depends_on": [{ "age5_known": 0 }, { "age5_known": 1 }] + "depends_on": [ + { + "age5_known": 0 + }, + { + "age5_known": 1 + } + ] } }, "age5": { @@ -3581,7 +3625,10 @@ "depends_on": [ { "details_known_5": 0, - "age5": { "operator": ">", "operand": 15 } + "age5": { + "operator": ">", + "operand": 15 + } }, { "details_known_5": 0, @@ -3765,7 +3812,14 @@ "age6": [0] }, "hidden_in_check_answers": { - "depends_on": [{ "age6_known": 0 }, { "age6_known": 1 }] + "depends_on": [ + { + "age6_known": 0 + }, + { + "age6_known": 1 + } + ] } }, "age6": { @@ -4053,7 +4107,10 @@ "depends_on": [ { "details_known_6": 0, - "age6": { "operator": ">", "operand": 15 } + "age6": { + "operator": ">", + "operand": 15 + } }, { "details_known_6": 0, @@ -4234,7 +4291,14 @@ "age7": [0] }, "hidden_in_check_answers": { - "depends_on": [{ "age7_known": 0 }, { "age7_known": 1 }] + "depends_on": [ + { + "age7_known": 0 + }, + { + "age7_known": 1 + } + ] } }, "age7": { @@ -4522,7 +4586,10 @@ "depends_on": [ { "details_known_7": 0, - "age7": { "operator": ">", "operand": 15 } + "age7": { + "operator": ">", + "operand": 15 + } }, { "details_known_7": 0, @@ -4700,7 +4767,14 @@ "age8": [0] }, "hidden_in_check_answers": { - "depends_on": [{ "age8_known": 0 }, { "age8_known": 1 }] + "depends_on": [ + { + "age8_known": 0 + }, + { + "age8_known": 1 + } + ] } }, "age8": { @@ -4988,7 +5062,10 @@ "depends_on": [ { "details_known_8": 0, - "age8": { "operator": ">", "operand": 15 } + "age8": { + "operator": ">", + "operand": 15 + } }, { "details_known_8": 0, @@ -5857,7 +5934,7 @@ "header": "", "description": "", "questions": { - "previous_postcode_known": { + "ppcodenk": { "header": "Do you know the postcode of the household’s last settled accommodation?", "hint_text": "This is also known as the household’s ‘last settled home’.", "type": "radio", @@ -5874,8 +5951,12 @@ }, "hidden_in_check_answers": { "depends_on": [ - { "previous_postcode_known": 0 }, - { "previous_postcode_known": 1 } + { + "ppcodenk": 0 + }, + { + "ppcodenk": 1 + } ] } }, @@ -5892,7 +5973,7 @@ }, "inferred_check_answers_value": { "condition": { - "previous_postcode_known": 0 + "ppcodenk": 0 }, "value": "Not known" } @@ -5910,8 +5991,12 @@ "type": "radio", "hidden_in_check_answers": { "depends_on": [ - { "previous_la_known": 0 }, - { "previous_la_known": 1 } + { + "previous_la_known": 0 + }, + { + "previous_la_known": 1 + } ] }, "answer_options": { diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json index 319a2ea05..0d9a97115 100644 --- a/config/forms/2022_2023.json +++ b/config/forms/2022_2023.json @@ -1016,7 +1016,7 @@ "header": "", "description": "", "questions": { - "shelteredaccom": { + "sheltered": { "check_answer_label": "Is this letting in sheltered accommodation?", "header": "Is this letting in sheltered accommodation?", "hint_text": "", @@ -5199,6 +5199,9 @@ }, "3": { "value": "Person prefers not to say" + }, + "6": { + "value": "Don’t know" } } } @@ -5560,9 +5563,6 @@ "hint_text": "", "type": "radio", "answer_options": { - "1": { - "value": "Just moved to local authority area" - }, "2": { "value": "Less than 1 year" }, @@ -5893,7 +5893,7 @@ "header": "", "description": "", "questions": { - "previous_postcode_known": { + "ppcodenk": { "header": "Do you know the postcode of the household’s last settled accommodation?", "hint_text": "This is also known as the household’s ‘last settled home’.", "type": "radio", @@ -5911,10 +5911,10 @@ "hidden_in_check_answers": { "depends_on": [ { - "previous_postcode_known": 0 + "ppcodenk": 0 }, { - "previous_postcode_known": 1 + "ppcodenk": 1 } ] } @@ -5932,7 +5932,7 @@ }, "inferred_check_answers_value": { "condition": { - "previous_postcode_known": 0 + "ppcodenk": 0 }, "value": "Not known" } diff --git a/config/forms/setup/log_setup.json b/config/forms/setup/log_setup.json new file mode 100644 index 000000000..e69de29bb diff --git a/db/migrate/20220613123730_add_export_fields.rb b/db/migrate/20220613123730_add_export_fields.rb new file mode 100644 index 000000000..eb2a03f84 --- /dev/null +++ b/db/migrate/20220613123730_add_export_fields.rb @@ -0,0 +1,13 @@ +class AddExportFields < ActiveRecord::Migration[7.0] + def change + change_table :case_logs, bulk: true do |t| + t.column :hhtype, :integer + t.column :new_old, :integer + t.column :vacdays, :integer + t.rename :tenant_code, :tenancycode + t.rename :previous_postcode_known, :ppcodenk + t.rename :shelteredaccom, :sheltered + t.remove :tenancy_code, type: :string + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d83363804..ca8c033ee 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -18,7 +18,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do t.integer "status", default: 0 t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "tenant_code" + t.string "tenancycode" t.integer "age1" t.string "sex1" t.integer "ethnic" @@ -53,7 +53,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do t.integer "reservist" t.integer "illness" t.integer "preg_occ" - t.string "tenancy_code" t.integer "startertenancy" t.integer "tenancylength" t.integer "tenancy" @@ -143,7 +142,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do t.decimal "tshortfall", precision: 10, scale: 2 t.decimal "chcharge", precision: 10, scale: 2 t.integer "declaration" - t.integer "previous_postcode_known" + t.integer "ppcodenk" t.integer "previous_la_known" t.boolean "is_previous_la_inferred" t.integer "age1_known" @@ -194,8 +193,11 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do t.integer "illness_type_0" t.integer "retirement_value_check" t.integer "tshortfall_known" - t.integer "shelteredaccom" + t.integer "sheltered" t.integer "pregnancy_value_check" + t.integer "hhtype" + t.integer "new_old" + t.integer "vacdays" 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 diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 8cb63643a..6ec46628a 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -11,7 +11,7 @@ FactoryBot.define do end trait :in_progress do status { 1 } - tenant_code { Faker::Name.initials(number: 10) } + tenancycode { Faker::Name.initials(number: 10) } postcode_full { Faker::Address.postcode } ppostcode_full { Faker::Address.postcode } age1 { 17 } @@ -27,7 +27,7 @@ FactoryBot.define do incfreq { 1 } end trait :conditional_section_complete do - tenant_code { Faker::Name.initials(number: 10) } + tenancycode { Faker::Name.initials(number: 10) } age1 { 34 } sex1 { "M" } ethnic { 2 } @@ -37,7 +37,7 @@ FactoryBot.define do end trait :completed do status { 2 } - tenant_code { Faker::Name.initials(number: 10) } + tenancycode { Faker::Name.initials(number: 10) } age1 { 35 } sex1 { "F" } ethnic { 2 } @@ -55,7 +55,6 @@ FactoryBot.define do reservist { 0 } illness { 1 } preg_occ { 2 } - tenancy_code { Faker::Name.initials(number: 10) } startertenancy { 0 } tenancylength { 5 } tenancy { 1 } @@ -132,7 +131,7 @@ FactoryBot.define do unitletas { 2 } has_benefits { 1 } is_carehome { 0 } - shelteredaccom { 0 } + sheltered { 0 } declaration { 1 } end created_at { Time.utc(2022, 2, 8, 16, 52, 15) } diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 08daa57a0..00766636c 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -148,7 +148,7 @@ RSpec.describe "Form Check Answers Page" do :in_progress, owning_organisation: user.organisation, managing_organisation: user.organisation, - tenant_code: "123", + tenancycode: "123", age1: 35, sex1: "M", hhmemb: 1, @@ -161,7 +161,7 @@ RSpec.describe "Form Check Answers Page" do :in_progress, owning_organisation: user.organisation, managing_organisation: user.organisation, - tenant_code: "123", + tenancycode: "123", age1: 35, sex1: "M", hhmemb: 1, @@ -176,7 +176,7 @@ RSpec.describe "Form Check Answers Page" do :in_progress, owning_organisation: user.organisation, managing_organisation: user.organisation, - tenant_code: "123", + tenancycode: "123", age1: 35, sex1: "M", hhmemb: 1, @@ -195,7 +195,7 @@ RSpec.describe "Form Check Answers Page" do owning_organisation: user.organisation, managing_organisation: user.organisation, needstype: 1, - tenant_code: nil, + tenancycode: nil, age1: nil, layear: 2, waityear: 1, @@ -221,7 +221,7 @@ RSpec.describe "Form Check Answers Page" do it "they can click a button to skip sections until the next incomplete section" do visit("/logs/#{skip_section_case_log.id}/household-characteristics/check-answers") click_link("Save and go to next incomplete section") - expect(page).to have_current_path("/logs/#{skip_section_case_log.id}/tenancy-code") + expect(page).to have_current_path("/logs/#{skip_section_case_log.id}/property-information/check-answers") end it "they can click a button to cycle around to the next incomplete section" do diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb index ac6116e84..1dbdaef25 100644 --- a/spec/features/form/form_navigation_spec.rb +++ b/spec/features/form/form_navigation_spec.rb @@ -16,7 +16,7 @@ RSpec.describe "Form Navigation" do let(:id) { case_log.id } let(:question_answers) do { - tenant_code: { type: "text", answer: "BZ737", path: "tenant-code-test" }, + tenancycode: { type: "text", answer: "BZ737", path: "tenant-code-test" }, age1: { type: "numeric", answer: 25, path: "person-1-age" }, sex1: { type: "radio", answer: "Female", path: "person-1-gender" }, ecstat1: { type: "radio", answer: 3, path: "person-1-working-situation" }, @@ -55,7 +55,7 @@ RSpec.describe "Form Navigation" do describe "Back link directs correctly", js: true do it "go back to tasklist page from tenant code" do visit("/logs/#{id}") - visit("/logs/#{id}/tenant-code") + visit("/logs/#{id}/tenant-code-test") click_link(text: "Back") expect(page).to have_content("Log #{id}") end @@ -65,7 +65,7 @@ RSpec.describe "Form Navigation" do click_button("Save and continue") visit("/logs/#{id}/person-1-age") click_link(text: "Back") - expect(page).to have_field("case-log-tenant-code-field") + expect(page).to have_field("case-log-tenancycode-field") end it "doesn't get stuck in infinite loops", js: true do diff --git a/spec/features/form/saving_data_spec.rb b/spec/features/form/saving_data_spec.rb index 863d906e7..97aeb7521 100644 --- a/spec/features/form/saving_data_spec.rb +++ b/spec/features/form/saving_data_spec.rb @@ -23,7 +23,7 @@ RSpec.describe "Form Saving Data" do end let(:question_answers) do { - tenant_code: { type: "text", answer: "BZ737", path: "tenant_code" }, + tenancycode: { type: "text", answer: "BZ737", path: "tenant-code-test" }, age1: { type: "numeric", answer: 25, path: "person_1_age" }, sex1: { type: "radio", answer: { "F" => "Female" }, path: "person_1_gender" }, hhmemb: { type: "numeric", answer: 3, path: "household_number_of_members" }, diff --git a/spec/features/form/tasklist_page_spec.rb b/spec/features/form/tasklist_page_spec.rb index 3c0da44b0..439a51515 100644 --- a/spec/features/form/tasklist_page_spec.rb +++ b/spec/features/form/tasklist_page_spec.rb @@ -50,7 +50,7 @@ RSpec.describe "Task List" do it "shows number of completed sections if one section is completed" do visit("/logs/#{setup_completed_log.id}") - expect(page).to have_content("1 of 10 sections completed.") + expect(page).to have_content("1 of 9 sections completed.") end it "show skip link for next incomplete section" do diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 620b697ed..d63e92160 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -1,6 +1,6 @@ { "case_log": { - "tenant_code": "T657", + "tenancycode": "T657", "age1": 35, "sex1": "F", "ethnic": 0, @@ -44,7 +44,6 @@ "reservist": 0, "illness": 1, "preg_occ": 1, - "tenancy_code": "BZ757", "startdate": "12/12/2021", "startertenancy": 0, "tenancylength": 5, @@ -132,7 +131,7 @@ "has_benefits": 1, "household_charge": 0, "is_carehome": 1, - "shelteredaccom": 0, + "sheltered": 0, "declaration": 1, "referral": 1 } diff --git a/spec/fixtures/exports/case_logs.csv b/spec/fixtures/exports/case_logs.csv index 1558c7ff1..95e47a3d6 100644 --- a/spec/fixtures/exports/case_logs.csv +++ b/spec/fixtures/exports/case_logs.csv @@ -1,2 +1,2 @@ -status,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,shelteredaccom,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate,tenancycode,ppcodenk -2,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,0,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,,200.0,50.0,40.0,35.0,325.0,12.0,,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC,BZ737,1 +status,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,ppcodenk,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,sheltered,hhtype,new_old,vacdays,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate +2,BZ737,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,0,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,,200.0,50.0,40.0,35.0,325.0,12.0,,1,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,0,4,2,638,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index 3c06ac5c1..469d8f2f0 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -2,6 +2,7 @@
2 + BZ737 35 F 2 @@ -108,6 +109,7 @@ 325.0 12.0 + 1 1 0 100.0 @@ -129,7 +131,10 @@ - 0 + 0 + 4 + 2 + 638 {id} {owning_org_id} DLUHC @@ -139,8 +144,6 @@ 1234 2022-02-08 16:52:15 UTC 2022-02-08 16:52:15 UTC - BZ737 - 1 1
diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 93f3166d1..97e150b4f 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -12,7 +12,7 @@ "pages": { "tenant_code_test": { "questions": { - "tenant_code": { + "tenancycode": { "check_answer_label": "Tenant code", "header": "What is the tenant code?", "hint_text": "This is how you usually refer to this tenancy on your own systems.", @@ -47,7 +47,7 @@ { "housingneeds_a": null } - ] + ] }, "person_1_gender": { "questions": { @@ -220,7 +220,7 @@ "header": "property reference?", "type": "text" } - } + } } } }, @@ -367,21 +367,6 @@ "tenancy_and_property": { "label": "Tenancy and property information", "subsections": { - "tenancy_information": { - "label": "Tenancy information", - "pages": { - "tenancy_code": { - "questions": { - "tenancy_code": { - "check_answer_label": "What is the tenancy code?", - "header": "What is the tenancy code?", - "type": "text", - "width": 10 - } - } - } - } - }, "property_information": { "label": "Property information", "pages": { @@ -983,7 +968,6 @@ "depends_on": [{ "household_characteristics": "completed", "household_needs": "completed", - "tenancy_information": "completed", "property_information": "completed" }], "pages": { diff --git a/spec/fixtures/forms/2022_2023.json b/spec/fixtures/forms/2022_2023.json index 9c8b60f89..a1b017d30 100644 --- a/spec/fixtures/forms/2022_2023.json +++ b/spec/fixtures/forms/2022_2023.json @@ -11,7 +11,7 @@ "pages": { "tenant_code_test": { "questions": { - "tenant_code": { + "tenancycode": { "check_answer_label": "Tenant code", "header": "Different question header text for this year - 2023", "type": "text", diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 5cc3b6fbb..daf7ba0d9 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -10,14 +10,14 @@ RSpec.describe TasklistHelper do end it "returns the first subsection name if it is partially completed" do - case_log["tenant_code"] = 123 + case_log["tenancycode"] = 123 expect(get_next_incomplete_section(case_log).id).to eq("setup") end end describe "get sections count" do it "returns the total of sections if no status is given" do - expect(get_subsections_count(empty_case_log)).to eq(10) + expect(get_subsections_count(empty_case_log)).to eq(9) end it "returns 0 sections for completed sections if no sections are completed" do @@ -25,7 +25,7 @@ RSpec.describe TasklistHelper do end it "returns the number of not started sections" do - expect(get_subsections_count(empty_case_log, :not_started)).to eq(9) + expect(get_subsections_count(empty_case_log, :not_started)).to eq(8) end it "returns the number of sections in progress" do @@ -45,7 +45,7 @@ RSpec.describe TasklistHelper do end it "returns the first question page path for the section if it has not been started yet" do - expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code/) + expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code-test/) end it "when first question being not routed to returns the next routed question link" do diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index b6941220c..77452b3bb 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1235,7 +1235,7 @@ RSpec.describe CaseLog do managing_organisation: owning_organisation, owning_organisation:, created_by: created_by_user, - previous_postcode_known: 1, + ppcodenk: 1, ppostcode_full: "M1 1AE", }) end @@ -1275,7 +1275,7 @@ RSpec.describe CaseLog do end it "correctly resets all fields if previous postcode not known" do - address_case_log.update!({ previous_postcode_known: 0 }) + address_case_log.update!({ ppcodenk: 0 }) record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0] expect(record_from_db["ppostcode_full"]).to eq(nil) @@ -1284,7 +1284,7 @@ RSpec.describe CaseLog do end it "correctly resets la if la is not known" do - address_case_log.update!({ previous_postcode_known: 0 }) + address_case_log.update!({ ppcodenk: 0 }) address_case_log.update!({ previous_la_known: 1, prevloc: "S92000003" }) record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0] expect(record_from_db["prevloc"]).to eq("S92000003") @@ -1297,7 +1297,7 @@ RSpec.describe CaseLog do end it "changes the prevloc if previous postcode changes from not known to known and provided" do - address_case_log.update!({ previous_postcode_known: 0 }) + address_case_log.update!({ ppcodenk: 0 }) address_case_log.update!({ previous_la_known: 1, prevloc: "E09000033" }) record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0] @@ -1305,7 +1305,7 @@ RSpec.describe CaseLog do expect(address_case_log.prevloc).to eq("E09000033") expect(record_from_db["prevloc"]).to eq("E09000033") - address_case_log.update!({ previous_postcode_known: 0, ppostcode_full: "M1 1AD" }) + address_case_log.update!({ ppcodenk: 0, ppostcode_full: "M1 1AD" }) record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0] expect(record_from_db["ppostcode_full"]).to eq("M11AD") @@ -1400,8 +1400,8 @@ RSpec.describe CaseLog do it "correctly derives and saves waityear" do record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["waityear"]).to eq(1) - expect(case_log["waityear"]).to eq(1) + expect(record_from_db["waityear"]).to eq(2) + expect(case_log["waityear"]).to eq(2) end it "correctly derives and saves underoccupation_benefitcap if year is 2021" do @@ -1757,8 +1757,8 @@ RSpec.describe CaseLog do case_log.update!({ renewal: 1 }) record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] - expect(record_from_db["waityear"]).to eq(1) - expect(case_log["waityear"]).to eq(1) + expect(record_from_db["waityear"]).to eq(2) + expect(case_log["waityear"]).to eq(2) case_log.update!({ renewal: 0 }) record_from_db = ActiveRecord::Base.connection.execute("select waityear from case_logs where id=#{case_log.id}").to_a[0] @@ -1891,13 +1891,13 @@ RSpec.describe CaseLog do describe "#filter_by_tenant_code" do it "allows searching by a Tenant Code" do - result = described_class.filter_by_tenant_code(case_log_to_search.tenant_code) + result = described_class.filter_by_tenant_code(case_log_to_search.tenancycode) expect(result.count).to eq(1) expect(result.first.id).to eq case_log_to_search.id end context "when tenant_code has lower case letters" do - let(:matching_tenant_code_lower_case) { case_log_to_search.tenant_code.downcase } + let(:matching_tenant_code_lower_case) { case_log_to_search.tenancycode.downcase } it "allows searching by a Tenant Code" do result = described_class.filter_by_tenant_code(matching_tenant_code_lower_case) @@ -1941,7 +1941,7 @@ RSpec.describe CaseLog do end it "allows searching using tenancy code" do - result = described_class.search_by(case_log_to_search.tenant_code) + result = described_class.search_by(case_log_to_search.tenancycode) expect(result.count).to eq(1) expect(result.first.id).to eq case_log_to_search.id end diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index 2b89df93e..804292f6c 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Form::Subsection, type: :model do end it "has questions" do - expected_questions = %w[tenant_code age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode] + expected_questions = %w[tenancycode age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode] expect(subsection.questions.map(&:id)).to eq(expected_questions) end @@ -73,7 +73,7 @@ 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 ecstat1 hhmemb ecstat2 propcode] + expected_questions = %w[tenancycode age1 sex1 ecstat1 hhmemb ecstat2 propcode] expect(subsection.applicable_questions(case_log).map(&:id)).to eq(expected_questions) expect(subsection.applicable_questions_count(case_log)).to eq(7) end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 8632e387a..d84d8751d 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(41) + expect(form.pages.count).to eq(40) end end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index eadaf2216..ffcb68f86 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -88,7 +88,7 @@ RSpec.describe Form, type: :model do end def answer_tenancy_information(case_log) - case_log.tenancy_code = "1234" + case_log.tenancycode = "1234" end def answer_property_information(case_log) @@ -126,7 +126,7 @@ RSpec.describe Form, type: :model do end before do - case_log.tenant_code = "123" + case_log.tenancycode = "123" case_log.age1 = 35 case_log.sex1 = "M" case_log.ecstat1 = 0 @@ -149,7 +149,7 @@ RSpec.describe Form, type: :model do it "returns the first page of the next incomplete subsection (skipping completed subsections)" do answer_household_needs(case_log) - expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("tenancy-code") + expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("accessible-select-too") end it "returns the declaration section for a completed case log" do diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index a8b217b02..7c00a1580 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -109,6 +109,8 @@ RSpec.describe Validations::FinancialValidations do end describe "housing benefit rent shortfall validations" do + before { record.startdate = Time.zone.local(2022, 5, 1) } + context "when shortfall is yes" do it "validates that housing benefit is not none" do record.hbrentshortfall = 1 @@ -126,7 +128,8 @@ RSpec.describe Validations::FinancialValidations do .to include(match I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")) end - it "validates that housing benefit is not Universal Credit without housing benefit" do + it "validates that housing benefit is not Universal Credit without housing benefit (prior to 22/23)" do + record.startdate = Time.zone.local(2022, 3, 1) record.hbrentshortfall = 1 record.hb = 7 financial_validator.validate_tshortfall(record) diff --git a/spec/models/validations/local_authority_validations_spec.rb b/spec/models/validations/local_authority_validations_spec.rb index 6ece1932c..83a7a7c83 100644 --- a/spec/models/validations/local_authority_validations_spec.rb +++ b/spec/models/validations/local_authority_validations_spec.rb @@ -14,21 +14,21 @@ RSpec.describe Validations::LocalAuthorityValidations do end it "does not add an error if the record ppostcode_full is valid (uppercase space)" do - record.previous_postcode_known = 1 + record.ppcodenk = 1 record.ppostcode_full = "M1 1AE" local_auth_validator.validate_previous_accommodation_postcode(record) expect(record.errors).to be_empty end it "does not add an error if the record ppostcode_full is valid (lowercase no space)" do - record.previous_postcode_known = 1 + record.ppcodenk = 1 record.ppostcode_full = "m11ae" local_auth_validator.validate_previous_accommodation_postcode(record) expect(record.errors).to be_empty end it "does add an error when the postcode is invalid" do - record.previous_postcode_known = 1 + record.ppcodenk = 1 record.ppostcode_full = "invalid" local_auth_validator.validate_previous_accommodation_postcode(record) expect(record.errors).not_to be_empty diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index e230b15c7..6a51d5d74 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -40,7 +40,7 @@ RSpec.describe CaseLogsController, type: :request do "owning_organisation_id": owning_organisation.id, "managing_organisation_id": managing_organisation.id, "created_by_id": user.id, - "tenant_code": tenant_code, + "tenancycode": tenant_code, "age1": age1, "postcode_full": postcode_full, "offered": offered, @@ -63,7 +63,7 @@ RSpec.describe CaseLogsController, type: :request do it "creates a case log with the values passed" do json_response = JSON.parse(response.body) - expect(json_response["tenant_code"]).to eq(tenant_code) + expect(json_response["tenancycode"]).to eq(tenant_code) expect(json_response["age1"]).to eq(age1) expect(json_response["postcode_full"]).to eq(postcode_full) end @@ -149,7 +149,7 @@ RSpec.describe CaseLogsController, type: :request do :case_log, owning_organisation: organisation, managing_organisation: organisation, - tenant_code: "LC783", + tenancycode: "LC783", ) end let!(:unauthorized_case_log) do @@ -157,7 +157,7 @@ RSpec.describe CaseLogsController, type: :request do :case_log, owning_organisation: other_organisation, managing_organisation: other_organisation, - tenant_code: "UA984", + tenancycode: "UA984", ) end @@ -289,7 +289,7 @@ RSpec.describe CaseLogsController, type: :request do startdate: Time.zone.local(2022, 12, 1), tenancy: 6, managing_organisation: organisation, - tenant_code: nil) + tenancycode: nil) end it "shows case logs for multiple selected statuses and years" do @@ -339,7 +339,7 @@ RSpec.describe CaseLogsController, type: :request do end it "shows case logs matching the tenant code" do - get "/logs?search=#{log_to_search.tenant_code}", headers: headers, params: {} + get "/logs?search=#{log_to_search.tenancycode}", headers: headers, params: {} expect(page).to have_link(log_to_search.id.to_s) logs.each do |log| expect(page).not_to have_link(log.id.to_s) @@ -487,8 +487,8 @@ RSpec.describe CaseLogsController, type: :request do let(:tenant_code_2) { "TC8745" } before do - FactoryBot.create(:case_log, :in_progress, owning_organisation: org_1, tenant_code: tenant_code_1) - FactoryBot.create(:case_log, :in_progress, owning_organisation: org_2, tenant_code: tenant_code_2) + FactoryBot.create(:case_log, :in_progress, owning_organisation: org_1, tenancycode: tenant_code_1) + FactoryBot.create(:case_log, :in_progress, owning_organisation: org_2, tenancycode: tenant_code_2) allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in user end @@ -624,7 +624,7 @@ RSpec.describe CaseLogsController, type: :request do it "displays a section status for a case log" do assert_select ".govuk-tag", text: /Not started/, count: 7 - assert_select ".govuk-tag", text: /In progress/, count: 2 + assert_select ".govuk-tag", text: /In progress/, count: 1 assert_select ".govuk-tag", text: /Completed/, count: 0 assert_select ".govuk-tag", text: /Cannot start yet/, count: 1 end @@ -752,7 +752,7 @@ RSpec.describe CaseLogsController, type: :request do expect(csv.second[10]).to eq("Full-time – 30 hours or more") end - it "dowloads filtered logs" do + it "downloads filtered logs" do get "/logs?status[]=completed", headers:, params: {} csv = CSV.parse(response.body) expect(csv.count).to eq(2) @@ -772,7 +772,7 @@ RSpec.describe CaseLogsController, type: :request do FactoryBot.create(:case_log, :completed, postcode_full: postcode, owning_organisation: organisation) end - it "dowloads logs matching both csv and filter logs" do + it "downloads logs matching both csv and filter logs" do get "/logs?status[]=completed&search=#{postcode}", headers:, params: {} csv = CSV.parse(response.body) expect(csv.count).to eq(2) @@ -796,10 +796,10 @@ RSpec.describe CaseLogsController, type: :request do describe "PATCH" do let(:case_log) do - FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "M1 1AE") + FactoryBot.create(:case_log, :in_progress, tenancycode: "Old Value", postcode_full: "M1 1AE") end let(:params) do - { tenant_code: "New Value" } + { tenancycode: "New Value" } end let(:id) { case_log.id } @@ -813,7 +813,7 @@ RSpec.describe CaseLogsController, type: :request do it "updates the case log with the given fields and keeps original values where none are passed" do case_log.reload - expect(case_log.tenant_code).to eq("New Value") + expect(case_log.tenancycode).to eq("New Value") expect(case_log.postcode_full).to eq("M11AE") end @@ -854,10 +854,10 @@ RSpec.describe CaseLogsController, type: :request do # what actually happens to an ActiveRecord object and what we're doing here, but either is allowed. describe "PUT" do let(:case_log) do - FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "SW1A 2AA") + FactoryBot.create(:case_log, :in_progress, tenancycode: "Old Value", postcode_full: "SW1A 2AA") end let(:params) do - { tenant_code: "New Value" } + { tenancycode: "New Value" } end let(:id) { case_log.id } @@ -871,7 +871,7 @@ RSpec.describe CaseLogsController, type: :request do it "updates the case log with the given fields and keeps original values where none are passed" do case_log.reload - expect(case_log.tenant_code).to eq("New Value") + expect(case_log.tenancycode).to eq("New Value") expect(case_log.postcode_full).to eq("SW1A2AA") end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index b0b2048a5..287d5d349 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -286,7 +286,7 @@ RSpec.describe FormController, type: :request do accessibility_requirements: %w[ housingneeds_a housingneeds_f], - tenant_code:, + tenancycode: tenant_code, }, } end @@ -306,7 +306,7 @@ RSpec.describe FormController, type: :request do "housingneeds_h" => "Don’t know" }, }, nil ), - Form::Question.new("tenant_code", { "type" => "text" }, nil), + Form::Question.new("tenancycode", { "type" => "text" }, nil), ] end let(:page) { case_log.form.get_page("accessibility_requirements") } @@ -318,7 +318,7 @@ RSpec.describe FormController, type: :request do expect(case_log.housingneeds_a).to eq(1) expect(case_log.housingneeds_f).to eq(1) - expect(case_log.tenant_code).to eq(tenant_code) + expect(case_log.tenancycode).to eq(tenant_code) end end end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 9179ec3b3..18fd10204 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -624,7 +624,7 @@ RSpec.describe OrganisationsController, type: :request do end it "shows case logs matching the tenant code" do - get "/organisations/#{organisation.id}/logs?search=#{log_to_search.tenant_code}", headers: headers, params: {} + get "/organisations/#{organisation.id}/logs?search=#{log_to_search.tenancycode}", headers: headers, params: {} expect(page).to have_link(log_to_search.id.to_s) logs.each do |log| expect(page).not_to have_link(log.id.to_s) diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index a7d907573..38692811e 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -312,7 +312,8 @@ RSpec.describe SchemesController, type: :request do end it "has correct title" do - expect(page).to have_title("#{scheme.service_name} - Submit social housing lettings and sales data (CORE) - GOV.UK") + expected_title = CGI.escapeHTML("#{scheme.service_name} - Submit social housing lettings and sales data (CORE) - GOV.UK") + expect(page).to have_title(expected_title) end context "when paginating over 20 results" do diff --git a/spec/services/exports/case_log_export_service_spec.rb b/spec/services/exports/case_log_export_service_spec.rb index e172716d9..a00ed6e49 100644 --- a/spec/services/exports/case_log_export_service_spec.rb +++ b/spec/services/exports/case_log_export_service_spec.rb @@ -47,7 +47,7 @@ RSpec.describe Exports::CaseLogExportService do end context "and one case log is available for export" do - let!(:case_log) { FactoryBot.create(:case_log, :completed, tenancy_code: "BZ757", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenant_code: "BZ737") } + let!(:case_log) { FactoryBot.create(:case_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737") } let(:expected_data_filename) { "core_2021_2022_jan_mar_f0001_inc0001_pt001.xml" } it "generates a ZIP export file with the expected filename" do @@ -226,7 +226,7 @@ RSpec.describe Exports::CaseLogExportService do let(:csv_export_file) { File.open("spec/fixtures/exports/case_logs.csv", "r:UTF-8") } let(:expected_csv_filename) { "export_2022_05_01.csv" } - let(:case_log) { FactoryBot.create(:case_log, :completed, tenancy_code: "BZ757", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenant_code: "BZ737") } + let(:case_log) { FactoryBot.create(:case_log, :completed, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737") } it "generates an CSV export file with the expected content" do expected_content = replace_entity_ids(case_log, csv_export_file.read) diff --git a/spec/services/imports/case_logs_field_import_service_spec.rb b/spec/services/imports/case_logs_field_import_service_spec.rb index 419ddbea3..d3776cb98 100644 --- a/spec/services/imports/case_logs_field_import_service_spec.rb +++ b/spec/services/imports/case_logs_field_import_service_spec.rb @@ -41,7 +41,7 @@ RSpec.describe Imports::CaseLogsFieldImportService do end context "when updating tenant code" do - let(:field) { "tenant_code" } + let(:field) { "tenancycode" } context "and the case log was previously imported" do let(:case_log) { CaseLog.find_by(old_id: case_log_id) } @@ -51,10 +51,10 @@ RSpec.describe Imports::CaseLogsFieldImportService do case_log_file.rewind end - it "logs that the tenant_code already has a value and does not update the case_log" do - expect(logger).to receive(:info).with(/Case Log \d+ has a value for tenant_code, skipping update/) + it "logs that the tenancycode already has a value and does not update the case_log" do + expect(logger).to receive(:info).with(/Case Log \d+ has a value for tenancycode, skipping update/) expect { import_service.send(:update_field, field, remote_folder) } - .not_to(change { case_log.reload.tenant_code }) + .not_to(change { case_log.reload.tenancycode }) end end @@ -64,12 +64,12 @@ RSpec.describe Imports::CaseLogsFieldImportService do before do Imports::CaseLogsImportService.new(storage_service, logger).create_logs(fixture_directory) case_log_file.rewind - case_log.update!(tenant_code: nil) + case_log.update!(tenancycode: nil) end it "updates the case_log" do expect { import_service.send(:update_field, field, remote_folder) } - .to(change { case_log.reload.tenant_code }) + .to(change { case_log.reload.tenancycode }) end end end