diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 8393a5c8e..d95a9cc89 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -38,8 +38,10 @@ class CaseLog < ApplicationRecord validates_with CaseLogValidator before_validation :process_postcode_changes!, if: :property_postcode_changed? + before_validation :process_previous_postcode_changes!, if: :previous_postcode_changed? before_validation :reset_invalidated_dependent_fields! before_validation :reset_location_fields!, unless: :postcode_known? + before_validation :reset_previous_location_fields!, unless: :previous_postcode_known? before_validation :set_derived_fields! before_save :update_status! @@ -49,7 +51,7 @@ class CaseLog < ApplicationRecord scope :for_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) } enum status: STATUS - enum letting_in_sheltered_accomodation: SHELTERED_ACCOMODATION + enum letting_in_sheltered_accommodation: SHELTERED_ACCOMMODATION enum ethnic: ETHNIC enum national: NATIONAL, _suffix: true enum ecstat1: ECSTAT, _suffix: true @@ -109,9 +111,9 @@ class CaseLog < ApplicationRecord enum rp_medwel: POLAR, _suffix: true enum rp_hardship: POLAR, _suffix: true enum rp_dontknow: POLAR, _suffix: true - enum cbl: POLAR2, _suffix: true - enum chr: POLAR2, _suffix: true - enum cap: POLAR2, _suffix: true + enum cbl: POLAR, _suffix: true + enum chr: POLAR, _suffix: true + enum cap: POLAR, _suffix: true enum wchair: POLAR2, _suffix: true enum incfreq: INCFREQ, _suffix: true enum benefits: BENEFITS, _suffix: true @@ -135,7 +137,9 @@ class CaseLog < ApplicationRecord enum needstype: NEEDS_TYPE, _suffix: true enum lettype: LET_TYPE, _suffix: true enum postcode_known: POLAR, _suffix: true + enum previous_postcode_known: POLAR, _suffix: true enum la_known: POLAR, _suffix: true + enum previous_la_known: POLAR, _suffix: true enum net_income_known: NET_INCOME_KNOWN, _suffix: true enum household_charge: POLAR, _suffix: true enum is_carehome: POLAR, _suffix: true @@ -180,6 +184,10 @@ class CaseLog < ApplicationRecord postcode_known == "Yes" end + def previous_postcode_known? + previous_postcode_known == "Yes" + end + def weekly_net_income return unless earnings && incfreq @@ -264,24 +272,40 @@ private end def process_postcode_changes! - return if property_postcode.blank? - - self.postcode_known = "Yes" - inferred_la = get_inferred_la(property_postcode) - self.is_la_inferred = inferred_la.present? - self.la = inferred_la if inferred_la.present? - self.postcode = UKPostcode.parse(property_postcode).outcode - self.postcod2 = UKPostcode.parse(property_postcode).incode + process_postcode(property_postcode, "postcode_known", "is_la_inferred", "la", "postcode", "postcod2") + end + + def process_previous_postcode_changes! + process_postcode(previous_postcode, "previous_postcode_known", "is_previous_la_inferred", "prevloc", "ppostc1", "ppostc2") + end + + def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key, outcode_key, incode_key) + return if postcode.blank? + + self[postcode_known_key] = "Yes" + inferred_la = get_inferred_la(postcode) + self[la_inferred_key] = inferred_la.present? + self[la_key] = inferred_la if inferred_la.present? + self[outcode_key] = UKPostcode.parse(postcode).outcode + self[incode_key] = UKPostcode.parse(postcode).incode end def reset_location_fields! - if is_la_inferred == true - self.la = nil + reset_location(is_la_inferred, "la", "is_la_inferred", "property_postcode", "postcode", "postcod2") + end + + def reset_previous_location_fields! + reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "previous_postcode", "ppostc1", "ppostc2") + end + + def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key) + if is_inferred + self[la_key] = nil end - self.is_la_inferred = false - self.property_postcode = nil - self.postcode = nil - self.postcod2 = nil + self[is_inferred_key] = false + self[postcode_key] = nil + self[incode_key] = nil + self[outcode_key] = nil end def get_totelder diff --git a/app/models/constants/case_log.rb b/app/models/constants/case_log.rb index b32c7ee04..229193c36 100644 --- a/app/models/constants/case_log.rb +++ b/app/models/constants/case_log.rb @@ -2,7 +2,7 @@ module Constants::CaseLog BENEFITCAP = { "Yes - benefit cap" => 5, "Yes - removal of the spare room subsidy" => 4, - "Yes - both the benefit cap and the removal of the spare room subsidy" => 6, + "Yes - both" => 6, "No" => 2, "Don’t know" => 3, "Prefer not to say" => 100, @@ -57,8 +57,8 @@ module Constants::CaseLog }.freeze HOMELESS = { - "Yes - assessed as homeless by a local authority and owed a homelessness duty. Including if threatened with homelessness within 56 days" => 11, - "Yes - other homelessness" => 7, + "Assessed as homeless (or threatened with homelessness within 56 days) by a local authority and owed a homelessness duty" => 11, + "Other homeless - not found statutorily homeless but considered homeless by landlord" => 7, "No" => 1, }.freeze @@ -104,11 +104,11 @@ module Constants::CaseLog PREVIOUS_TENANCY = { "Owner occupation (private)" => 26, - "Owner occupation (low cost home ownership)" => 27, + "Owner occupation (low-cost home ownership)" => 27, "Private sector tenancy" => 3, "Tied housing or rented with job" => 4, "Supported housing" => 6, - "Sheltered accomodation" => 8, + "Sheltered accommodation" => 8, "Residential care home" => 9, "Living with friends or family" => 28, "Refuge" => 21, @@ -121,11 +121,11 @@ module Constants::CaseLog "Home Office Asylum Support" => 24, "Children’s home or foster care" => 13, "Rough sleeping" => 19, - "Other" => 25, - "Fixed term Local Authority General Needs tenancy" => 30, - "Lifetime Local Authority General Needs tenancy" => 31, - "Fixed term PRP General Needs tenancy" => 32, - "Lifetime PRP General Needs tenancy" => 33, + "Any other accommodation" => 25, + "Fixed-term local authority general needs tenancy" => 30, + "Lifetime local authority general needs tenancy" => 31, + "Fixed-term private registered provider (PRP) general needs tenancy" => 32, + "Lifetime private registered provider (PRP) general needs tenancy" => 33, }.freeze RESERVIST = { @@ -219,10 +219,10 @@ module Constants::CaseLog LATIME = { "Just moved to local authority area" => 1, "Less than 1 year" => 2, - "1 to 2 years" => 7, - "2 to 3 years" => 8, - "3 to 4 years" => 9, - "4 to 5 years" => 10, + "1 year but under 2 years" => 7, + "2 years but under 3 years" => 8, + "3 years but under 4 years" => 9, + "4 years but under 5 years" => 10, "5 years or more" => 5, "Don’t know" => 6, }.freeze @@ -242,36 +242,36 @@ module Constants::CaseLog "Left home country as a refugee" => 2, "Loss of tied accommodation" => 4, "Domestic abuse" => 7, - "(Non violent) relationship breakdown with partner" => 8, + "Relationship breakdown (non-violent) with partner" => 8, "Asked to leave by family or friends" => 9, "Racial harassment" => 10, "Other problems with neighbours" => 11, "Property unsuitable because of overcrowding" => 12, "End of assured shorthold tenancy - no fault" => 40, - "End of assured shorthold tenancy - tenant’s fault" => 41, + "End of assured shorthold tenancy - eviction or tenant at fault" => 41, "End of fixed term tenancy - no fault" => 42, - "End of fixed term tenancy - tenant’s fault" => 43, + "End of fixed term tenancy - eviction or tenant at fault" => 43, "Repossession" => 34, "Under occupation - offered incentive to downsize" => 29, "Under occupation - no incentive" => 30, - "Property unsuitable because of ill health / disability" => 13, + "Property unsuitable because of ill health or disability" => 13, "Property unsuitable because of poor condition" => 14, - "Couldn't afford fees attached to renewing the tenancy" => 35, - "Couldn't afford increase in rent" => 36, - "Couldn't afford rent or mortgage - welfare reforms" => 37, - "Couldn't afford rent or mortgage - employment" => 38, - "Couldn't afford rent or mortgage - other" => 39, - "To move nearer to family / friends / school" => 16, + "Couldn’t afford fees attached to renewing the tenancy" => 35, + "Couldn’t afford increase in rent" => 36, + "Couldn’t afford rent or mortgage - welfare reforms" => 37, + "Couldn’t afford rent or mortgage - employment" => 38, + "Couldn’t afford rent or mortgage - other" => 39, + "To move nearer to family, friends or school" => 16, "To move nearer to work" => 17, - "To move to accomodation with support" => 18, - "To move to independent accomodation" => 19, + "To move to accommodation with support" => 18, + "To move to independent accommodation" => 19, "Hate crime" => 31, - "Death of household member in last settled accomodation" => 46, + "Death of household member in last settled accommodation" => 46, "Discharged from prison" => 44, "Discharged from long stay hospital or similar institution" => 45, "Other" => 20, "Don’t know" => 28, - "Prefer not to say" => 100, + "Tenant prefers not to say" => 100, }.freeze ENGLISH_LA = { @@ -1087,7 +1087,7 @@ module Constants::CaseLog "completed" => 2, }.freeze - SHELTERED_ACCOMODATION = { + SHELTERED_ACCOMMODATION = { "Yes - sheltered housing" => 1, "Yes - extra care housing" => 2, "No" => 3, @@ -1119,9 +1119,9 @@ module Constants::CaseLog NON_TEMP_ACCOMMODATION = ["Tied housing or rented with job", "Supported housing", - "Sheltered accomodation", + "Sheltered accommodation", "Home Office Asylum Support", - "Other"].freeze + "Any other accommodation"].freeze OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze end diff --git a/app/models/form/page.rb b/app/models/form/page.rb index 3d9719397..ad8a4a8af 100644 --- a/app/models/form/page.rb +++ b/app/models/form/page.rb @@ -44,12 +44,19 @@ private }.compact end + def send_chain(arr, case_log) + Array(arr).inject(case_log) { |o, a| o.public_send(*a) } + end + def depends_on_met(case_log) return true unless depends_on depends_on.any? do |conditions_set| conditions_set.all? do |question, value| - value.nil? ? case_log[question] == value : !case_log[question].nil? && case_log[question] == value + parts = question.split(".") + case_log_value = send_chain(parts, case_log) + + value.nil? ? case_log_value == value : !case_log_value.nil? && case_log_value == value end end end diff --git a/app/models/validations/local_authority_validations.rb b/app/models/validations/local_authority_validations.rb index b241e158e..2b00c52e5 100644 --- a/app/models/validations/local_authority_validations.rb +++ b/app/models/validations/local_authority_validations.rb @@ -4,7 +4,7 @@ module Validations::LocalAuthorityValidations def validate_previous_accommodation_postcode(record) postcode = record.previous_postcode - if postcode.present? && !postcode.match(POSTCODE_REGEXP) + if record.previous_postcode_known == "Yes" && (postcode.blank? || !postcode.match(POSTCODE_REGEXP)) error_message = I18n.t("validations.postcode") record.errors.add :previous_postcode, error_message end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 551e7491d..321797c09 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1113,7 +1113,7 @@ "questions": { "layear": { "check_answer_label": "How long has the household continuously lived in the local authority area where the new letting is located?", - "header": "How long has the household continuously lived in the local authority area where the new letting is located?", + "header": "How long has the household continuously lived in the local authority area of the new letting?", "hint_text": "", "type": "radio", "answer_options": { @@ -1124,25 +1124,25 @@ "value": "Less than 1 year" }, "2": { - "value": "1 to 2 years" + "value": "1 year but under 2 years" }, "3": { - "value": "2 to 3 years" + "value": "2 years but under 3 years" }, "4": { - "value": "3 to 4 years" + "value": "3 years but under 4 years" }, "5": { - "value": "4 to 5 years" + "value": "4 years but under 5 years" }, "6": { "value": "5 years or more" }, - "7": { - "value": "Don’t know" - }, "divider": { "value": true + }, + "7": { + "value": "Don’t know" } } } @@ -1154,7 +1154,7 @@ "questions": { "lawaitlist": { "check_answer_label": "How long has the household been on the local authority waiting list where the new letting is located?", - "header": "How long has the household been on the local authority waiting list where the new letting is located?", + "header": "How long has the household been on the local authority waiting list for the new letting?", "hint_text": "", "type": "radio", "answer_options": { @@ -1165,183 +1165,154 @@ "value": "Less than 1 year" }, "2": { - "value": "1 to 2 years" + "value": "1 year but under 2 years" }, "3": { - "value": "2 to 3 years" + "value": "2 years but under 3 years" }, "4": { - "value": "3 to 4 years" + "value": "3 years but under 4 years" }, "5": { - "value": "4 to 5 years" + "value": "4 years but under 5 years" }, "6": { "value": "5 years or more" }, - "7": { - "value": "Don’t know" - }, "divider": { "value": true + }, + "7": { + "value": "Don’t know" } } } - } + }, + "depends_on": [{ "renewal": "No" }] }, "reason_for_leaving_last_settled_home": { "header": "Leaving their last settled home", "description": "", "questions": { "reason": { - "header": "What is the tenant’s main reason for leaving?", - "hint_text": "", + "header": "What is the tenant’s main reason for the household leaving their last settled home?", + "hint_text": "The tenant’s ’last settled home’ is their last long-standing home. For tenants who were in temporary accommodation or sleeping rough, their last settled home is where they were living previously.", "type": "radio", "answer_options": { "0": { - "value": "Permanently decanted from another property owned by this landlord" + "value": "End of assured shorthold tenancy - no fault" }, "1": { - "value": "Left home country as a refugee" + "value": "End of assured shorthold tenancy - eviction or tenant at fault" }, "2": { - "value": "Loss of tied accommodation" + "value": "End of fixed term tenancy - no fault" }, "3": { - "value": "Domestic abuse" + "value": "End of fixed term tenancy - eviction or tenant at fault" }, "4": { - "value": "(Non violent) relationship breakdown with partner" + "value": "Permanently decanted from another property owned by this landlord" }, "5": { - "value": "Asked to leave by family or friends" + "value": "Left home country as a refugee" }, "6": { - "value": "Racial harassment" + "value": "Discharged from prison" }, "7": { - "value": "Other problems with neighbours" + "value": "Discharged from long stay hospital or similar institution" }, "8": { - "value": "Property unsuitable because of overcrowding" + "value": "Loss of tied accommodation" }, "9": { - "value": "End of assured shorthold tenancy - no fault" + "value": "Asked to leave by family or friends" }, "10": { - "value": "End of assured shorthold tenancy - tenant’s fault" + "value": "Relationship breakdown (non-violent) with partner" }, "11": { - "value": "End of fixed term tenancy - no fault" + "value": "Death of household member in last settled accommodation" }, "12": { - "value": "End of fixed term tenancy - tenant’s fault" + "value": "To move nearer to family, friends or school" }, "13": { - "value": "Repossession" + "value": "To move nearer to work" }, "14": { - "value": "Under occupation - offered incentive to downsize" + "value": "Domestic abuse" }, "15": { - "value": "Under occupation - no incentive" + "value": "Racial harassment" }, "16": { - "value": "Property unsuitable because of ill health / disability" + "value": "Hate crime" }, "17": { - "value": "Property unsuitable because of poor condition" + "value": "Other problems with neighbours" }, "18": { - "value": "Couldn’t afford fees attached to renewing the tenancy" + "value": "Repossession" }, "19": { - "value": "Couldn’t afford increase in rent" + "value": "Couldn’t afford fees attached to renewing the tenancy" }, "20": { - "value": "Couldn’t afford rent or mortgage - welfare reforms" + "value": "Couldn’t afford increase in rent" }, "21": { - "value": "Couldn’t afford rent or mortgage - employment" + "value": "Couldn’t afford rent or mortgage - welfare reforms" }, "22": { - "value": "Couldn’t afford rent or mortgage - other" + "value": "Couldn’t afford rent or mortgage - employment" }, "23": { - "value": "To move nearer to family / friends / school" + "value": "Couldn’t afford rent or mortgage - other" }, "24": { - "value": "To move nearer to work" + "value": "Property unsuitable because of overcrowding" }, "25": { - "value": "To move to accomodation with support" + "value": "Property unsuitable because of ill health or disability" }, "26": { - "value": "To move to independent accomodation" + "value": "Property unsuitable because of poor condition" }, "27": { - "value": "Hate crime" + "value": "Under occupation - no incentive" }, "28": { - "value": "Death of household member in last settled accomodation" + "value": "Under occupation - offered incentive to downsize" }, "29": { - "value": "Discharged from prison" + "value": "To move to accommodation with support" }, "30": { - "value": "Discharged from long stay hospital or similar institution" + "value": "To move to independent accommodation" }, "31": { "value": "Other" }, + "divider": { + "value": true + }, "32": { "value": "Don’t know" }, "33": { - "value": "Prefer not to say" - }, - "divider": { - "value": true + "value": "Tenant prefers not to say" } }, "conditional_for": { - "other_reason_for_leaving_last_settled_home": [ - "Other" - ] + "other_reason_for_leaving_last_settled_home": ["Other"] } }, "other_reason_for_leaving_last_settled_home": { - "header": "Please state the reason for leaving last settled home", + "header": "What is the reason?", "hint_text": "", "type": "text" - }, - "underoccupation_benefitcap": { - "header": "Was the reason for leaving because of the benefit cap or removal of the spare room subsidy?", - "hint_text": "", - "type": "radio", - "answer_options": { - "0": { - "value": "Yes - benefit cap" - }, - "1": { - "value": "Yes - removal of the spare room subsidy" - }, - "2": { - "value": "Yes - both the benefit cap and the removal of the spare room subsidy" - }, - "3": { - "value": "No" - }, - "4": { - "value": "Don’t know" - }, - "5": { - "value": "Prefer not to say" - }, - "divider": { - "value": true - } - } } } }, @@ -1350,21 +1321,21 @@ "description": "", "questions": { "prevten": { - "header": "What was the tenant’s housing situation immediately before this letting?", - "hint_text": "", + "header": "Where was the household immediately before this letting?", + "hint_text": "This is where the household was the night before they moved.", "type": "radio", "answer_options": { "0": { - "value": "Owner occupation (private)" + "value": "Fixed-term local authority general needs tenancy" }, "1": { - "value": "Owner occupation (low cost home ownership)" + "value": "Lifetime local authority general needs tenancy" }, "2": { - "value": "Private sector tenancy" + "value": "Fixed-term private registered provider (PRP) general needs tenancy" }, "3": { - "value": "Tied housing or rented with job" + "value": "Lifetime private registered provider (PRP) general needs tenancy" }, "4": { "value": "Supported housing" @@ -1373,55 +1344,86 @@ "value": "Sheltered accommodation" }, "6": { - "value": "Residential care home" + "value": "Private sector tenancy" }, "7": { - "value": "Living with friends or family" + "value": "Owner occupation (private)" }, "8": { - "value": "Refuge" + "value": "Owner occupation (low-cost home ownership)" }, "9": { - "value": "Hospital" + "value": "Living with friends or family" }, "10": { - "value": "Prison or approved probation hostel" + "value": "Direct access hostel" }, "11": { - "value": "Direct access hostel" + "value": "Bed and breakfast" }, "12": { - "value": "Bed and breakfast" + "value": "Prison or approved probation hostel" }, "13": { - "value": "Mobile home or caravan" + "value": "Hospital" }, "14": { "value": "Any other temporary accommodation" }, "15": { - "value": "Home Office Asylum Support" + "value": "Rough sleeping" }, "16": { - "value": "Children’s home or foster care" + "value": "Tied housing or rented with job" }, "17": { - "value": "Rough sleeping" + "value": "Mobile home or caravan" }, "18": { - "value": "Other" + "value": "Refuge" }, "19": { - "value": "Fixed term Local Authority General Needs tenancy" + "value": "Children’s home or foster care" }, "20": { - "value": "Lifetime Local Authority General Needs tenancy" + "value": "Residential care home" }, "21": { - "value": "Fixed term PRP General Needs tenancy" + "value": "Home Office Asylum Support" }, "22": { - "value": "Lifetime PRP General Needs tenancy" + "value": "Any other accommodation" + } + } + } + } + }, + "underoccupation_benefitcap": { + "header": "", + "description": "", + "questions": { + "underoccupation_benefitcap": { + "header": "Was the reason for leaving a direct result of the removal of the spare room subsidy or benefit cap introduced from 2013?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": { + "value": "Yes - removal of the spare room subsidy" + }, + "1": { + "value": "Yes - benefit cap" + }, + "2": { + "value": "Yes - both" + }, + "3": { + "value": "No" + }, + "divider": { + "value": true + }, + "4": { + "value": "Don’t know" } } } @@ -1432,15 +1434,15 @@ "description": "", "questions": { "homeless": { - "header": "Did the tenant experience homelessness immediately before this letting?", + "header": "Did the household experience homelessness immediately before this letting?", "hint_text": "", "type": "radio", "answer_options": { "0": { - "value": "Yes - assessed as homeless by a local authority and owed a homelessness duty. Including if threatened with homelessness within 56 days" + "value": "Assessed as homeless (or threatened with homelessness within 56 days) by a local authority and owed a homelessness duty" }, "1": { - "value": "Yes - other homelessness" + "value": "Other homeless - not found statutorily homeless but considered homeless by landlord" }, "2": { "value": "No" @@ -1449,6 +1451,57 @@ } } }, + "previous_postcode": { + "header": "", + "description": "", + "questions": { + "previous_postcode_known": { + "check_answer_label": "Do you know the postcode of the household’s last settled accommodation?", + "header": "Do you know the property’s postcode?", + "hint_text": "This is also known as the household’s ’last settled home’.", + "type": "radio", + "answer_options": { + "1": { "value": "Yes" }, + "0": { "value": "No" } + }, + "conditional_for": { + "previous_postcode": ["Yes"] + }, + "hidden_in_check_answers": true + }, + "previous_postcode": { + "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", + "header": "Postcode for the previous accommodation", + "hint_text": "", + "type": "text", + "width": 5, + "inferred_answers": { + "prevloc": { "is_previous_la_inferred": true } + }, + "inferred_check_answers_value": { + "condition": { "previous_postcode_known": "No" }, + "value": "Not known" + } + } + } + }, + "previous_la_known": { + "header": "", + "description": "", + "questions": { + "previous_la_known": { + "check_answer_label": "Do you know the local authority of the household’s last settled accommodation?", + "header": "Do you know the local authority of the household’s last settled accommodation?", + "hint_text": "This is also known as the household’s ’last settled home’.", + "type": "radio", + "answer_options": { + "1": { "value": "Yes" }, + "0": { "value": "No" } + } + } + }, + "depends_on": [{ "is_previous_la_inferred": false }] + }, "previous_la": { "header": "", "description": "", @@ -1845,28 +1898,19 @@ "9300000XX": "Outside UK" } } - } - }, - "previous_postcode": { - "header": "", - "description": "", - "questions": { - "previous_postcode": { - "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", - "header": "Postcode for the previous accommodation", - "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed.", - "type": "text" - } - } + }, + "depends_on": [ + { "previous_la_known": "Yes", "is_previous_la_inferred": false } + ] }, "reasonable_preference": { "header": "", "description": "", "questions": { "reasonpref": { - "check_answer_label": "Was the household given Reasonable Preference (i.e. priority) for housing by the Local Authority?", - "header": "Was the household given reasonable preference by the local authority?", - "hint_text": "", + "check_answer_label": "Was the household given ‘reasonable preference’ by the local authority?", + "header": "Was the household given ‘reasonable preference’ by the local authority?", + "hint_text": "Households may be given ‘reasonable preference’ for social housing, also known as ‘priority need’, by the local authority.", "type": "radio", "answer_options": { "0": { @@ -1875,11 +1919,11 @@ "1": { "value": "No" }, - "2": { - "value": "Don’t know" - }, "divider": { "value": true + }, + "2": { + "value": "Don’t know" } } } @@ -1888,29 +1932,24 @@ "reasonable_preference_reason": { "header": "Reason for reasonable preference being given", "description": "", - "depends_on": [ - { - "reasonpref": "Yes" - } - ], "questions": { "reasonable_preference_reason": { "check_answer_label": "Reason for reasonable preference", - "header": "Why were they given reasonable preference?", - "hint_text": "Select all that apply.", + "header": "Why was the household given ‘reasonable preference’?", + "hint_text": "", "type": "checkbox", "answer_options": { "rp_homeless": { - "value": "Homeless or about to lose their home (within 56 days)" + "value": "They were homeless or about to lose their home (within 56 days)" }, "rp_insan_unsat": { - "value": "Living in insanitary or overcrowded or unsatisfactory housing" + "value": "They were living in unsanitary, overcrowded or unsatisfactory housing" }, "rp_medwel": { - "value": "A need to move on medical and welfare grounds (including a disability)" + "value": "They needed to move due to medical and welfare reasons (including disability)" }, "rp_hardship": { - "value": "A need to move to avoid hardship to themselves or others" + "value": "They needed to move to avoid hardship to themselves or others" }, "divider": { "value": true @@ -1920,57 +1959,208 @@ } } } - } + }, + "depends_on": [ + { + "reasonpref": "Yes" + } + ] }, "lettings_policy": { "header": "", "description": "", "questions": { - "cbl": { - "check_answer_label": "Choice-based letting?", - "header": "Was the letting made under choice-based lettings (CBL)? ", + "letting_allocation": { + "check_answer_label": "How was this letting allocated?", + "header": "How was this letting allocated?", + "hint_text": "Select all that apply.", + "type": "checkbox", + "answer_options": { + "cbl": { + "value": "Choice-based lettings (CBL)" + }, + "chr": { + "value": "Common housing register (CHR)" + }, + "cap": { + "value": "Common Allocation Policy (CAP)" + }, + "divider": { + "value": true + }, + "letting_allocation_unknown": { + "value": "None of these allocation systems" + } + } + } + } + }, + "referral": { + "header": "", + "description": "", + "questions": { + "referral": { + "check_answer_label": "Source of referral for letting", + "header": "What was the source of referral for this letting?", "hint_text": "", "type": "radio", "answer_options": { "0": { - "value": "Yes" + "value": "Internal transfer" }, "1": { - "value": "No" + "value": "Tenant applied directly (no referral or nomination)" + }, + "2": { + "value": "Re-located through official housing mobility scheme" + }, + "3": { + "value": "Other social landlord" + }, + "4": { + "value": "Community learning disability team" + }, + "5": { + "value": "Community mental health team" + }, + "6": { + "value": "Health service" + }, + "7": { + "value": "Police, probation or prison" + }, + "8": { + "value": "Youth offending team" + }, + "9": { + "value": "Voluntary agency" + }, + "10": { + "value": "Other" } } - }, - "chr": { - "check_answer_label": "Common housing register letting?", - "header": "Was the letting made under common housing register (CHR)? ", + } + }, + "depends_on": [ + { + "managing_organisation.provider_type": "LA", + "needstype": "General needs" + } + ] + }, + "referral_prp": { + "header": "", + "description": "", + "questions": { + "referral": { + "check_answer_label": "Source of referral for letting", + "header": "What was the source of referral for this letting?", "hint_text": "", "type": "radio", "answer_options": { "0": { - "value": "Yes" + "value": "Internal transfer" }, "1": { - "value": "No" + "value": "Tenant applied directly (no referral or nomination)" + }, + "2": { + "value": "Private registered provider (PRP) lettings only - nominated by a local housing authority" + }, + "3": { + "value": "Re-located through official housing mobility scheme" + }, + "4": { + "value": "Other social landlord" + }, + "5": { + "value": "Community learning disability team" + }, + "6": { + "value": "Community mental health team" + }, + "7": { + "value": "Health service" + }, + "8": { + "value": "Police, probation or prison" + }, + "9": { + "value": "Youth offending team" + }, + "10": { + "value": "Voluntary agency" + }, + "11": { + "value": "Other" } } - }, - "cap": { - "check_answer_label": "Common allocation policy letting?", - "header": "Was the letting made under common allocation policy (CAP)? ", + } + }, + "depends_on": [ + { + "managing_organisation.provider_type": "PRP", + "needstype": "General needs" + } + ] + }, + "referral_supported_housing": { + "header": "", + "description": "", + "questions": { + "referral": { + "check_answer_label": "Source of referral for letting", + "header": "What was the source of referral for this letting?", "hint_text": "", "type": "radio", "answer_options": { "0": { - "value": "Yes" + "value": "Internal transfer" }, "1": { - "value": "No" + "value": "Tenant applied directly (no referral or nomination)" + }, + "2": { + "value": "Private registered provider (PRP) supported lettings only - referred by local authority housing department" + }, + "3": { + "value": "Re-located through official housing mobility scheme" + }, + "4": { + "value": "Other social landlord" + }, + "5": { + "value": "Community learning disability team" + }, + "6": { + "value": "Community mental health team" + }, + "7": { + "value": "Health service" + }, + "8": { + "value": "Police, probation or prison" + }, + "9": { + "value": "Youth offending team" + }, + "10": { + "value": "Voluntary agency" + }, + "11": { + "value": "Other" } } } - } + }, + "depends_on": [ + { + "managing_organisation.provider_type": "LA", + "needstype": "Supported housing" + } + ] }, - "referral": { + "referral_supported_housing_prp": { "header": "", "description": "", "questions": { @@ -2002,16 +2192,16 @@ "value": "Community learning disability team" }, "7": { - "value": "Police, probation or prison" + "value": "Community mental health team" }, "8": { - "value": "Youth offending team" + "value": "Health service" }, "9": { - "value": "Community mental health team" + "value": "Police, probation or prison" }, "10": { - "value": "Health service" + "value": "Youth offending team" }, "11": { "value": "Voluntary agency" @@ -2021,7 +2211,13 @@ } } } - } + }, + "depends_on": [ + { + "managing_organisation.provider_type": "PRP", + "needstype": "Supported housing" + } + ] } } }, @@ -2318,9 +2514,7 @@ } }, "conditional_for": { - "tenancyother": [ - "Other" - ] + "tenancyother": ["Other"] } }, "tenancyother": { @@ -2362,9 +2556,7 @@ } }, "conditional_for": { - "tenancyother": [ - "Other" - ] + "tenancyother": ["Other"] } }, "tenancyother": { @@ -2394,19 +2586,15 @@ } }, "depends_on": [ - { - "tenancy": "Secure (including flexible)" - }, - { - "tenancy": "Assured Shorthold" - } + { "tenancy": "Secure (including flexible)" }, + { "tenancy": "Assured Shorthold" } ] }, - "letting_in_sheltered_accomodation": { + "letting_in_sheltered_accommodation": { "header": "", "description": "", "questions": { - "letting_in_sheltered_accomodation": { + "letting_in_sheltered_accommodation": { "check_answer_label": "Is this letting in sheltered accommodation?", "header": "Is this letting in sheltered accommodation?", "hint_text": "", @@ -2464,9 +2652,7 @@ } }, "conditional_for": { - "property_postcode": [ - "Yes" - ] + "property_postcode": ["Yes"] }, "hidden_in_check_answers": true }, @@ -3197,9 +3383,7 @@ } }, "conditional_for": { - "mrcdate": [ - "Yes" - ] + "mrcdate": ["Yes"] } }, "mrcdate": { @@ -3273,9 +3457,18 @@ "width": 5, "prefix": "£", "suffix": [ - { "label": "every week", "depends_on" : { "incfreq": "Weekly" } }, - { "label": "every month", "depends_on" : { "incfreq": "Monthly" } }, - { "label": "every month", "depends_on" : { "incfreq": "Yearly" } } + { + "label": "every week", + "depends_on": { "incfreq": "Weekly" } + }, + { + "label": "every month", + "depends_on": { "incfreq": "Monthly" } + }, + { + "label": "every month", + "depends_on": { "incfreq": "Yearly" } + } ] }, "incfreq": { @@ -3466,9 +3659,7 @@ } }, "conditional_for": { - "chcharge": [ - "Yes" - ] + "chcharge": ["Yes"] } }, "chcharge": { @@ -3562,9 +3753,7 @@ } }, "conditional_for": { - "chcharge": [ - "Yes" - ] + "chcharge": ["Yes"] } }, "chcharge": { @@ -3608,9 +3797,7 @@ } }, "conditional_for": { - "chcharge": [ - "Yes" - ] + "chcharge": ["Yes"] } }, "chcharge": { @@ -3654,9 +3841,7 @@ } }, "conditional_for": { - "chcharge": [ - "Yes" - ] + "chcharge": ["Yes"] } }, "chcharge": { @@ -3696,12 +3881,7 @@ "width": 5, "prefix": "£", "suffix": " every week", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -3715,12 +3895,7 @@ "width": 5, "prefix": "£", "suffix": " every week", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -3734,12 +3909,7 @@ "width": 5, "prefix": "£", "suffix": " every week", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -3753,12 +3923,7 @@ "width": 5, "prefix": "£", "suffix": " every week", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -3774,12 +3939,7 @@ "suffix": " every week", "readonly": true, "requires_js": true, - "fields_added": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ] + "fields_added": ["brent", "scharge", "pscharge", "supcharg"] } }, "depends_on": [ @@ -3919,12 +4079,7 @@ "width": 5, "prefix": "£", "suffix": " every 2 weeks", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -3938,31 +4093,21 @@ "width": 5, "prefix": "£", "suffix": " every 2 weeks", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, "pscharge": { "check_answer_label": "Personal service charge", "header": "What is the personal service charge?", - "hint_text": "For example, for heating or hot water. This doesn't include housing benefit or Universal Credit.", + "hint_text": "For example, for heating or hot water. This doesn’t include housing benefit or Universal Credit.", "type": "numeric", "min": 0, "step": 1, "width": 5, "prefix": "£", "suffix": " every 2 weeks", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -3976,12 +4121,7 @@ "width": 5, "prefix": "£", "suffix": " every 2 weeks", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -3997,12 +4137,7 @@ "suffix": " every 2 weeks", "readonly": true, "requires_js": true, - "fields_added": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ] + "fields_added": ["brent", "scharge", "pscharge", "supcharg"] } }, "depends_on": [ @@ -4042,12 +4177,7 @@ "width": 5, "prefix": "£", "suffix": " every 4 weeks", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -4061,12 +4191,7 @@ "width": 5, "prefix": "£", "suffix": " every 4 weeks", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -4080,12 +4205,7 @@ "width": 5, "prefix": "£", "suffix": " every 4 weeks", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -4099,12 +4219,7 @@ "width": 5, "prefix": "£", "suffix": " every 4 weeks", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -4120,12 +4235,7 @@ "suffix": " every 4 weeks", "readonly": true, "requires_js": true, - "fields_added": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ] + "fields_added": ["brent", "scharge", "pscharge", "supcharg"] } }, "depends_on": [ @@ -4165,12 +4275,7 @@ "width": 5, "prefix": "£", "suffix": " every month", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -4184,31 +4289,21 @@ "width": 5, "prefix": "£", "suffix": " every month", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, "pscharge": { "check_answer_label": "Personal service charge", "header": "What is the personal service charge?", - "hint_text": "For example, for heating or hot water. This doesn't include housing benefit or Universal Credit.", + "hint_text": "For example, for heating or hot water. This doesn’t include housing benefit or Universal Credit.", "type": "numeric", "min": 0, "step": 1, "width": 5, "prefix": "£", "suffix": " every month", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -4222,12 +4317,7 @@ "width": 5, "prefix": "£", "suffix": " every month", - "fields-to-add": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ], + "fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "result-field": "tcharge", "hidden_in_check_answers": true }, @@ -4243,12 +4333,7 @@ "suffix": " every month", "readonly": true, "requires_js": true, - "fields_added": [ - "brent", - "scharge", - "pscharge", - "supcharg" - ] + "fields_added": ["brent", "scharge", "pscharge", "supcharg"] } }, "depends_on": [ diff --git a/db/migrate/20220209105333_fix_typo.rb b/db/migrate/20220209105333_fix_typo.rb new file mode 100644 index 000000000..91ad9a847 --- /dev/null +++ b/db/migrate/20220209105333_fix_typo.rb @@ -0,0 +1,9 @@ +class FixTypo < ActiveRecord::Migration[7.0] + def up + rename_column :case_logs, :letting_in_sheltered_accomodation, :letting_in_sheltered_accommodation + end + + def down + rename_column :case_logs, :letting_in_sheltered_accommodation, :letting_in_sheltered_accomodation + end +end diff --git a/db/migrate/20220209132411_add_previous_postcode_known.rb b/db/migrate/20220209132411_add_previous_postcode_known.rb new file mode 100644 index 000000000..ac865614b --- /dev/null +++ b/db/migrate/20220209132411_add_previous_postcode_known.rb @@ -0,0 +1,7 @@ +class AddPreviousPostcodeKnown < ActiveRecord::Migration[7.0] + change_table :case_logs, bulk: true do |t| + t.column :previous_postcode_known, :integer + t.column :previous_la_known, :integer + t.column :is_previous_la_inferred, :boolean + end +end diff --git a/db/migrate/20220209155009_add_unknown_letting_allocation.rb b/db/migrate/20220209155009_add_unknown_letting_allocation.rb new file mode 100644 index 000000000..6dd62cd91 --- /dev/null +++ b/db/migrate/20220209155009_add_unknown_letting_allocation.rb @@ -0,0 +1,7 @@ +class AddUnknownLettingAllocation < ActiveRecord::Migration[7.0] + def change + change_table :case_logs, bulk: true do |t| + t.column :letting_allocation_unknown, :boolean + end + end +end diff --git a/db/schema.rb b/db/schema.rb index bd49638f9..b45d23e7b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -176,7 +176,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.string "has_benefits" t.integer "nocharge" t.integer "is_carehome" - t.integer "letting_in_sheltered_accomodation" + t.integer "letting_in_sheltered_accommodation" t.integer "household_charge" t.integer "referral" t.decimal "brent", precision: 10, scale: 2 @@ -187,6 +187,10 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) 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 "previous_la_known" + t.boolean "is_previous_la_inferred" + t.boolean "letting_allocation_unknown" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" end diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index d5394f06a..46443d4c6 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -331,7 +331,7 @@ "supcharg": 35, "tcharge": 325, "tshortfall": "Yes", - "layear": "1 to 2 years", + "layear": "1 year but under 2 years", "lawaitlist": "Less than 1 year", "prevloc": "Ashford", "property_postcode": "SE2 6RT", @@ -733,36 +733,36 @@ "Left home country as a refugee", "Loss of tied accommodation", "Domestic abuse", - "(Non violent) relationship breakdown with partner", + "Relationship breakdown (non-violent) with partner", "Asked to leave by family or friends", "Racial harassment", "Other problems with neighbours", "Property unsuitable because of overcrowding", "End of assured shorthold tenancy - no fault", - "End of assured shorthold tenancy - tenant’s fault", + "End of assured shorthold tenancy - eviction or tenant at fault", "End of fixed term tenancy - no fault", - "End of fixed term tenancy - tenant’s fault", + "End of fixed term tenancy - eviction or tenant at fault", "Repossession", "Under occupation - offered incentive to downsize", "Under occupation - no incentive", - "Property unsuitable because of ill health / disability", + "Property unsuitable because of ill health or disability", "Property unsuitable because of poor condition", "Couldn’t afford fees attached to renewing the tenancy", "Couldn’t afford increase in rent", "Couldn’t afford rent or mortgage - welfare reforms", "Couldn’t afford rent or mortgage - employment", "Couldn’t afford rent or mortgage - other", - "To move nearer to family / friends / school", + "To move nearer to family, friends or school", "To move nearer to work", - "To move to accomodation with support", - "To move to independent accomodation", + "To move to accommodation with support", + "To move to independent accommodation", "Hate crime", - "Death of household member in last settled accomodation", + "Death of household member in last settled accommodation", "Discharged from prison", "Discharged from long stay hospital or similar institution", "Other", "Don’t know", - "Prefer not to say" + "Tenant prefers not to say" ] }, "underoccupation_benefitcap": { @@ -771,7 +771,7 @@ "enum": [ "Yes - benefit cap", "Yes - removal of the spare room subsidy", - "Yes - both the benefit cap and the removal of the spare room subsidy", + "Yes - both", "No", "Don’t know", "Prefer not to say" diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 0f0367f84..aea1e11d1 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -47,7 +47,7 @@ FactoryBot.define do age2 { 32 } sex2 { "Male" } ecstat2 { "Not seeking work" } - homeless { "Yes - other homelessness" } + homeless { "Other homeless - not found statutorily homeless but considered homeless by landlord" } underoccupation_benefitcap { "No" } leftreg { "No - they left up to 5 years ago" } reservist { "No" } @@ -75,7 +75,7 @@ FactoryBot.define do pscharge { 40 } supcharg { 35 } tcharge { 325 } - layear { "1 to 2 years" } + layear { "1 year but under 2 years" } lawaitlist { "Less than 1 year" } property_postcode { "NW1 5TY" } reasonpref { "Yes" } @@ -144,7 +144,7 @@ FactoryBot.define do has_benefits { "Yes" } is_carehome { "No" } chcharge { 7 } - letting_in_sheltered_accomodation { "No" } + letting_in_sheltered_accommodation { "No" } la_known { "Yes" } declaration { "Yes" } end diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 131b63bc8..b92153877 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -179,7 +179,7 @@ RSpec.describe "Form Check Answers Page" do managing_organisation: user.organisation, tenant_code: nil, age1: nil, - layear: "1 to 2 years", + layear: "1 year but under 2 years", lawaitlist: "Less than 1 year", property_postcode: "NW1 5TY", reason: "Permanently decanted from another property owned by this landlord", diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index f98c80d70..c5532f1c5 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -84,7 +84,7 @@ "supcharg": 35, "tcharge": 325, "outstanding_amount": "Yes", - "layear": "1 to 2 years", + "layear": "1 year but under 2 years", "lawaitlist": "Less than 1 year", "prevloc": "Ashford", "previous_postcode": "SE2 6RT", @@ -143,7 +143,7 @@ "household_charge": "Yes", "is_carehome": "Yes", "chcharge": "6", - "letting_in_sheltered_accomodation": "No", + "letting_in_sheltered_accommodation": "No", "declaration": "Yes" } } diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index 7b2181582..63d5f3822 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -41,7 +41,7 @@ - Yes - other homelessness + Other homeless - not found statutorily homeless but considered homeless by landlord No No - they left up to 5 years ago No @@ -62,7 +62,7 @@ Weekly Some Every 2 weeks - 1 to 2 years + 1 year but under 2 years Less than 1 year NW1 5TY Yes @@ -144,7 +144,7 @@ Yes No No - No + No Yes 200.0 @@ -155,6 +155,10 @@ 12.0 7.0 Yes + Yes + + false +
{id_2} @@ -197,7 +201,7 @@ - Yes - other homelessness + Other homeless - not found statutorily homeless but considered homeless by landlord No No - they left up to 5 years ago No @@ -218,7 +222,7 @@ Weekly Some Every 2 weeks - 1 to 2 years + 1 year but under 2 years Less than 1 year NW1 5TY Yes @@ -300,7 +304,7 @@ Yes No No - No + No Yes 200.0 @@ -311,5 +315,9 @@ 12.0 7.0 Yes + Yes + + false + diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 9958ec25a..c26509345 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -688,16 +688,16 @@ "value": "Less than 1 year" }, "2": { - "value": "1 to 2 years" + "value": "1 year but under 2 years" }, "3": { - "value": "2 to 3 years" + "value": "2 years but under 3 years" }, "4": { - "value": "3 to 4 years" + "value": "3 years but under 4 years" }, "5": { - "value": "4 to 5 years" + "value": "4 years but under 5 years" }, "6": { "value": "5 years or more" @@ -726,16 +726,16 @@ "value": "Less than 1 year" }, "2": { - "value": "1 to 2 years" + "value": "1 year but under 2 years" }, "3": { - "value": "2 to 3 years" + "value": "2 years but under 3 years" }, "4": { - "value": "3 to 4 years" + "value": "3 years but under 4 years" }, "5": { - "value": "4 to 5 years" + "value": "4 years but under 5 years" }, "6": { "value": "5 years or more" @@ -753,7 +753,7 @@ "property_postcode": { "questions": { "property_postcode": { - "check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation", + "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", "header": "Postcode for the previous accommodation", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", "type": "text", @@ -761,7 +761,7 @@ "conditional_for": { "fake_key": "fake_condition" } }, "previous_postcode": { - "check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation", + "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", "header": "Postcode for the previous accommodation", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", "type": "text", diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 56abae011..44c47a88c 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -781,15 +781,15 @@ RSpec.describe CaseLog do }.to raise_error(ActiveRecord::RecordInvalid) end - it "cannot be temp accomodation if previous tenancy was non temp" do + it "cannot be temp accommodation if previous tenancy was non temp" do check_rsnvac_validation("Tied housing or rented with job") check_rsnvac_validation("Supported housing") - check_rsnvac_validation("Sheltered accomodation") + check_rsnvac_validation("Sheltered accommodation") check_rsnvac_validation("Home Office Asylum Support") - check_rsnvac_validation("Other") + check_rsnvac_validation("Any other accommodation") end - it "cannot be temp accomodation if source of letting referral " do + it "cannot be temp accommodation if source of letting referral " do check_rsnvac_referral_validation("Re-located through official housing mobility scheme") check_rsnvac_referral_validation("Other social landlord") check_rsnvac_referral_validation("Police, probation or prison") @@ -987,6 +987,64 @@ RSpec.describe CaseLog do end end + context "when saving previous address" do + before do + stub_request(:get, /api.postcodes.io/) + .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\"}}", headers: {}) + end + + let!(:address_case_log) do + described_class.create({ + managing_organisation: organisation, + owning_organisation: organisation, + previous_postcode_known: "Yes", + previous_postcode: "M1 1AE", + }) + end + + it "correctly infers prevloc" do + record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0] + expect(address_case_log.prevloc).to eq("Manchester") + expect(record_from_db["prevloc"]).to eq("E08000003") + end + + it "errors if the previous postcode is emptied" do + expect { address_case_log.update!({ previous_postcode: "" }) } + .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) + end + + it "errors if the previous postcode is not valid" do + expect { address_case_log.update!({ previous_postcode: "invalid_postcode" }) } + .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) + end + + it "correctly resets all fields if previous postcode not known" do + address_case_log.update!({ previous_postcode_known: "No" }) + + record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0] + expect(record_from_db["previous_postcode"]).to eq(nil) + expect(address_case_log.prevloc).to eq(nil) + expect(record_from_db["prevloc"]).to eq(nil) + end + + it "changes the prevloc if previous postcode changes from not known to known and provided" do + address_case_log.update!({ previous_postcode_known: "No" }) + address_case_log.update!({ prevloc: "Westminster" }) + + record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0] + expect(record_from_db["previous_postcode"]).to eq(nil) + expect(address_case_log.prevloc).to eq("Westminster") + expect(record_from_db["prevloc"]).to eq("E09000033") + + address_case_log.update!({ previous_postcode_known: "Yes", previous_postcode: "M1 1AD" }) + + record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0] + expect(record_from_db["previous_postcode"]).to eq("M1 1AD") + expect(address_case_log.prevloc).to eq("Manchester") + expect(record_from_db["prevloc"]).to eq("E08000003") + end + end + context "when saving rent and charges" do let!(:case_log) do described_class.create({ diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 93bca44c3..685a20212 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -77,7 +77,7 @@ RSpec.describe Form, type: :model do end def answer_local_authority(case_log) - case_log.layear = "1 to 2 years" + case_log.layear = "1 year but under 2 years" case_log.lawaitlist = "Less than 1 year" case_log.property_postcode = "NW1 5TY" case_log.reason = "Permanently decanted from another property owned by this landlord" diff --git a/spec/models/validations/local_authority_validations_spec.rb b/spec/models/validations/local_authority_validations_spec.rb index dc5bebe3d..0c4c27313 100644 --- a/spec/models/validations/local_authority_validations_spec.rb +++ b/spec/models/validations/local_authority_validations_spec.rb @@ -14,18 +14,21 @@ RSpec.describe Validations::LocalAuthorityValidations do end it "does not add an error if the record previous_postcode is valid (uppercase space)" do + record.previous_postcode_known = "Yes" record.previous_postcode = "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 previous_postcode is valid (lowercase no space)" do + record.previous_postcode_known = "Yes" record.previous_postcode = "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 = "Yes" record.previous_postcode = "invalid" local_auth_validator.validate_previous_accommodation_postcode(record) expect(record.errors).not_to be_empty