From c309a4760bf45a1625a573ef22edb5404e96ff34 Mon Sep 17 00:00:00 2001 From: Robert Sullivan Date: Tue, 16 Apr 2024 11:31:17 +0100 Subject: [PATCH] CLDC-3384 referral tests and inconsistencies (#2370) * CLDC-3156: Update 2024 referral options * CLDC-3156: Add tests for referral question * CLDC-3156: Update other referral questions * CLDC-3384: Referral question inconsistencies and tests * feat: remove option 4 from 24/25 referral * feat: update tests --------- Co-authored-by: natdeanlewissoftwire --- .../form/lettings/questions/referral_prp.rb | 7 +- .../questions/referral_supported_housing.rb | 10 +- .../validations/household_validations.rb | 4 - config/locales/en.yml | 2 - .../lettings/questions/referral_prp_spec.rb | 104 +++++++++++++++++ .../referral_supported_housing_prp_spec.rb | 105 ++++++++++++++++++ .../referral_supported_housing_spec.rb | 101 +++++++++++++++++ .../validations/household_validations_spec.rb | 18 --- 8 files changed, 314 insertions(+), 37 deletions(-) create mode 100644 spec/models/form/lettings/questions/referral_prp_spec.rb create mode 100644 spec/models/form/lettings/questions/referral_supported_housing_prp_spec.rb create mode 100644 spec/models/form/lettings/questions/referral_supported_housing_spec.rb diff --git a/app/models/form/lettings/questions/referral_prp.rb b/app/models/form/lettings/questions/referral_prp.rb index c5549ce49..6a8fa63de 100644 --- a/app/models/form/lettings/questions/referral_prp.rb +++ b/app/models/form/lettings/questions/referral_prp.rb @@ -18,14 +18,11 @@ class Form::Lettings::Questions::ReferralPrp < ::Form::Question "hint" => "Where the tenant has moved to another social property owned by the same landlord.", }, "2" => { - "value" => "Tenant applied directly (no nomination)", + "value" => "Tenant applied directly (no referral or nomination)", }, "3" => { "value" => "Nominated by a local housing authority", }, - "4" => { - "value" => "Referred by local authority housing department", - }, "8" => { "value" => "Re-located through official housing mobility scheme", }, @@ -64,7 +61,7 @@ class Form::Lettings::Questions::ReferralPrp < ::Form::Question "hint" => "Where the tenant has moved to another social property owned by the same landlord.", }, "2" => { - "value" => "Tenant applied directly (no nomination)", + "value" => "Tenant applied directly (no referral or nomination)", }, "3" => { "value" => "Nominated by a local housing authority", diff --git a/app/models/form/lettings/questions/referral_supported_housing.rb b/app/models/form/lettings/questions/referral_supported_housing.rb index 642d2eb16..d9ede5a83 100644 --- a/app/models/form/lettings/questions/referral_supported_housing.rb +++ b/app/models/form/lettings/questions/referral_supported_housing.rb @@ -18,10 +18,7 @@ class Form::Lettings::Questions::ReferralSupportedHousing < ::Form::Question "hint" => "Where the tenant has moved to another social property owned by the same landlord.", }, "2" => { - "value" => "Tenant applied directly (no referral)", - }, - "3" => { - "value" => "Nominated by a local housing authority", + "value" => "Tenant applied directly (no referral or nomination)", }, "8" => { "value" => "Re-located through official housing mobility scheme", @@ -61,10 +58,7 @@ class Form::Lettings::Questions::ReferralSupportedHousing < ::Form::Question "hint" => "Where the tenant has moved to another social property owned by the same landlord.", }, "2" => { - "value" => "Tenant applied directly (no referral)", - }, - "3" => { - "value" => "Nominated by a local housing authority", + "value" => "Tenant applied directly (no referral or nomination)", }, "8" => { "value" => "Re-located through official housing mobility scheme", diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index 52c1de668..2fc3cf6c9 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -178,10 +178,6 @@ module Validations::HouseholdValidations record.errors.add :prevten, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.prevten.la_general_needs.internal_transfer") record.errors.add :referral, :internal_transfer_fixed_or_lifetime, message: I18n.t("validations.household.referral.la_general_needs.internal_transfer") end - - if record.owning_organisation.provider_type == "LA" && record.local_housing_referral? - record.errors.add :referral, I18n.t("validations.household.referral.prp.local_housing_referral") - end end def validate_prevloc(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index 68bea0c8f..ef8674c44 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -533,8 +533,6 @@ en: la_general_needs: internal_transfer: "Answer cannot be internal transfer as it’s the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting" prp_referred_by_la: "The source of the referral cannot be referred by local authority housing department for a general needs log" - prp: - local_housing_referral: "Answer cannot be ‘nominated by a local housing authority’ as a local authority is on the tenancy agreement" homeless: assessed: internal_transfer: "Answer cannot be 'assessed as homeless' as this tenancy is an internal transfer" diff --git a/spec/models/form/lettings/questions/referral_prp_spec.rb b/spec/models/form/lettings/questions/referral_prp_spec.rb new file mode 100644 index 000000000..f0fdb47e7 --- /dev/null +++ b/spec/models/form/lettings/questions/referral_prp_spec.rb @@ -0,0 +1,104 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::ReferralPrp, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(false) + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("referral") + end + + it "has the correct header" do + expect(question.header).to eq("What was the source of referral for this letting?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Source of referral for letting") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(0) + end + + it "has the correct hint" do + expect(question.hint_text).to eq("You told us that the needs type is general needs. We have removed some options because of this.") + end + + it "is not marked as derived" do + expect(question).not_to be_derived(nil) + end + + context "with 2023/24 form" do + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Internal transfer", "hint" => "Where the tenant has moved to another social property owned by the same landlord." }, + "2" => { "value" => "Tenant applied directly (no referral or nomination)" }, + "3" => { "value" => "Nominated by a local housing authority" }, + "4" => { "value" => "Referred by local authority housing department" }, + "8" => { "value" => "Re-located through official housing mobility scheme" }, + "10" => { "value" => "Other social landlord" }, + "9" => { "value" => "Community learning disability team" }, + "14" => { "value" => "Community mental health team" }, + "15" => { "value" => "Health service" }, + "12" => { "value" => "Police, probation or prison" }, + "7" => { "value" => "Voluntary agency" }, + "13" => { "value" => "Youth offending team" }, + "17" => { "value" => "Children’s Social Care" }, + "16" => { "value" => "Other" }, + }) + end + + it "has the correct question number" do + expect(question.question_number).to eq(85) + end + end + + context "with 2024/25 form" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(true) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Internal transfer", "hint" => "Where the tenant has moved to another social property owned by the same landlord." }, + "2" => { "value" => "Tenant applied directly (no referral or nomination)" }, + "3" => { "value" => "Nominated by a local housing authority" }, + "8" => { "value" => "Re-located through official housing mobility scheme" }, + "10" => { "value" => "Other social landlord" }, + "9" => { "value" => "Community learning disability team" }, + "14" => { "value" => "Community mental health team" }, + "15" => { "value" => "Health service" }, + "18" => { "value" => "Police, probation, prison or youth offending team – tenant had custodial sentence" }, + "19" => { "value" => "Police, probation, prison or youth offending team – no custodial sentence" }, + "7" => { "value" => "Voluntary agency" }, + "17" => { "value" => "Children’s Social Care" }, + "16" => { "value" => "Other" }, + }) + end + + it "has the correct question number" do + expect(question.question_number).to eq(84) + end + end +end diff --git a/spec/models/form/lettings/questions/referral_supported_housing_prp_spec.rb b/spec/models/form/lettings/questions/referral_supported_housing_prp_spec.rb new file mode 100644 index 000000000..de209092c --- /dev/null +++ b/spec/models/form/lettings/questions/referral_supported_housing_prp_spec.rb @@ -0,0 +1,105 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::ReferralSupportedHousingPrp, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(false) + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("referral") + end + + it "has the correct header" do + expect(question.header).to eq("What was the source of referral for this letting?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Source of referral for letting") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(0) + end + + it "has the correct hint" do + expect(question.hint_text).to eq("") + end + + it "is not marked as derived" do + expect(question).not_to be_derived(nil) + end + + context "with 2023/24 form" do + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Internal transfer", "hint" => "Where the tenant has moved to another social property owned by the same landlord." }, + "2" => { "value" => "Tenant applied directly (no referral or nomination)" }, + "3" => { "value" => "Nominated by a local housing authority" }, + "4" => { "value" => "Referred by local authority housing department" }, + "8" => { "value" => "Re-located through official housing mobility scheme" }, + "10" => { "value" => "Other social landlord" }, + "9" => { "value" => "Community learning disability team" }, + "14" => { "value" => "Community mental health team" }, + "15" => { "value" => "Health service" }, + "12" => { "value" => "Police, probation or prison" }, + "7" => { "value" => "Voluntary agency" }, + "13" => { "value" => "Youth offending team" }, + "17" => { "value" => "Children’s Social Care" }, + "16" => { "value" => "Other" }, + }) + end + + it "has the correct question number" do + expect(question.question_number).to eq(85) + end + end + + context "with 2024/25 form" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(true) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Internal transfer", "hint" => "Where the tenant has moved to another social property owned by the same landlord." }, + "2" => { "value" => "Tenant applied directly (no referral or nomination)" }, + "3" => { "value" => "Nominated by a local housing authority" }, + "4" => { "value" => "Referred by local authority housing department" }, + "8" => { "value" => "Re-located through official housing mobility scheme" }, + "10" => { "value" => "Other social landlord" }, + "9" => { "value" => "Community learning disability team" }, + "14" => { "value" => "Community mental health team" }, + "15" => { "value" => "Health service" }, + "18" => { "value" => "Police, probation, prison or youth offending team – tenant had custodial sentence" }, + "19" => { "value" => "Police, probation, prison or youth offending team – no custodial sentence" }, + "7" => { "value" => "Voluntary agency" }, + "17" => { "value" => "Children’s Social Care" }, + "16" => { "value" => "Other" }, + }) + end + + it "has the correct question number" do + expect(question.question_number).to eq(84) + end + end +end diff --git a/spec/models/form/lettings/questions/referral_supported_housing_spec.rb b/spec/models/form/lettings/questions/referral_supported_housing_spec.rb new file mode 100644 index 000000000..0a09415a6 --- /dev/null +++ b/spec/models/form/lettings/questions/referral_supported_housing_spec.rb @@ -0,0 +1,101 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Questions::ReferralSupportedHousing, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1)) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(false) + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("referral") + end + + it "has the correct header" do + expect(question.header).to eq("What was the source of referral for this letting?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Source of referral for letting") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(0) + end + + it "has the correct hint" do + expect(question.hint_text).to eq("You told us that you are a local authority. We have removed some options because of this.") + end + + it "is not marked as derived" do + expect(question).not_to be_derived(nil) + end + + context "with 2023/24 form" do + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Internal transfer", "hint" => "Where the tenant has moved to another social property owned by the same landlord." }, + "2" => { "value" => "Tenant applied directly (no referral or nomination)" }, + "8" => { "value" => "Re-located through official housing mobility scheme" }, + "10" => { "value" => "Other social landlord" }, + "9" => { "value" => "Community learning disability team" }, + "14" => { "value" => "Community mental health team" }, + "15" => { "value" => "Health service" }, + "12" => { "value" => "Police, probation or prison" }, + "7" => { "value" => "Voluntary agency" }, + "13" => { "value" => "Youth offending team" }, + "17" => { "value" => "Children’s Social Care" }, + "16" => { "value" => "Other" }, + }) + end + + it "has the correct question number" do + expect(question.question_number).to eq(85) + end + end + + context "with 2024/25 form" do + let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) } + + before do + allow(form).to receive(:start_year_after_2024?).and_return(true) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Internal transfer", "hint" => "Where the tenant has moved to another social property owned by the same landlord." }, + "2" => { "value" => "Tenant applied directly (no referral or nomination)" }, + "8" => { "value" => "Re-located through official housing mobility scheme" }, + "10" => { "value" => "Other social landlord" }, + "9" => { "value" => "Community learning disability team" }, + "14" => { "value" => "Community mental health team" }, + "15" => { "value" => "Health service" }, + "18" => { "value" => "Police, probation, prison or youth offending team – tenant had custodial sentence" }, + "19" => { "value" => "Police, probation, prison or youth offending team – no custodial sentence" }, + "7" => { "value" => "Voluntary agency" }, + "17" => { "value" => "Children’s Social Care" }, + "16" => { "value" => "Other" }, + }) + end + + it "has the correct question number" do + expect(question.question_number).to eq(84) + end + end +end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 1c0be2133..c5f59da93 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -177,24 +177,6 @@ RSpec.describe Validations::HouseholdValidations do .to include(match(I18n.t("validations.household.prevten.la_general_needs.internal_transfer"))) end end - - context "when referral is nominated by a local housing authority" do - it "cannot have a local authority" do - record.owning_organisation.provider_type = "LA" - record.referral = 3 - household_validator.validate_referral(record) - expect(record.errors["referral"]) - .to include(match(I18n.t("validations.household.referral.prp.local_housing_referral"))) - end - - it "can have a private registered provider" do - record.owning_organisation.provider_type = "PRP" - record.referral = 3 - household_validator.validate_referral(record) - expect(record.errors["referral"]) - .to be_empty - end - end end describe "armed forces validations" do