diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 723dbeceb..0ef775c11 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -38,6 +38,12 @@ class CaseLogValidator < ActiveModel::Validator record.errors.add :other_reason_for_leaving_last_settled_home, "The other reason must not be provided if the reason for leaving settled home was not other" end end + + def validate_reason_for_leaving_last_settled_home(record) + if record.reason_for_leaving_last_settled_home == "Do not know" && record.benefit_cap_spare_room_subsidy != "Do not know" + record.errors.add :benefit_cap_spare_room_subsidy, "must be do not know if tenant’s main reason for leaving is do not know" + end + end def validate_net_income(record) return unless record.tenant_economic_status && record.weekly_net_income diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 47378e9f0..1d2d72b57 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -612,7 +612,7 @@ "header": "Leaving their last settled home", "description": "", "questions": { - "last_settled_home": { + "reason_for_leaving_last_settled_home": { "header": "What is the tenant’s main reason for leaving?", "hint_text": "", "type": "radio", diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index 015e98a07..374c30bfb 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -193,7 +193,7 @@ "summary": "Create New Case Log", "operationId": "post-caselog", "responses": { - "200": { + "201": { "description": "Case Log Created", "content": { "application/json": { @@ -781,11 +781,55 @@ }, "reason_for_leaving_last_settled_home": { "type": "string", - "minLength": 1 + "minLength": 1, + "enum": [ + "Permanently decanted from another property owned by this landlord", + "Left home country as a refugee", + "Loss of tied accommodation", + "Domestic abuse", + "(Non violent) relationship breakdown 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 fixed term tenancy - no fault", + "End of fixed term tenancy - tenant's fault", + "Repossession", + "Under occupation - offered incentive to downsize", + "Under occupation - no incentive", + "Property unsuitable because of ill health / 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 work", + "To move to accomodation with support", + "To move to independent accomodation", + "Hate crime", + "Death of household member in last settled accomodation", + "Discharged from prison", + "Discharged from long stay hospital or similar institution", + "Other", + "Do not know", + "Prefer not to say" + ] }, "benefit_cap_spare_room_subsidy": { "type": "string", - "minLength": 1 + "minLength": 1, + "enum": [ + "Yes - benefit cap", + "Yes - removal of the spare room subsidy", + "Yes - both the benefit cap and the removal of the spare room subsidy", + "No", + "Do not know", + "Prefer not to say" + ] }, "armed_forces_active": { "type": "string", @@ -1158,4 +1202,4 @@ }, "securitySchemes": {} } -} +} \ No newline at end of file diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index bb217fa75..f9e33afd7 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -81,7 +81,14 @@ RSpec.describe Form, type: :model do }.to raise_error(ActiveRecord::RecordInvalid) end end - + context "reason for leaving last settled home validation" do + it "Reason for leaving must be don't know if reason for leaving settled home (Q9a) is don't know." do + expect { + CaseLog.create!(reason_for_leaving_last_settled_home: "Do not know", + benefit_cap_spare_room_subsidy: "Yes - benefit cap") + }.to raise_error(ActiveRecord::RecordInvalid) + end + end context "other reason for leaving last settled home validation" do it "must be provided if main reason for leaving last settled home was given as other" do expect {