From cd9b9167b89c3eae65d03de661313bf47f7bcd43 Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Thu, 29 Jan 2026 17:20:12 +0000 Subject: [PATCH] CLDC-4189: Add tests --- .../lettings/pages/referral_noms_hr_spec.rb | 79 +++++++++ .../pages/referral_noms_la_hr_spec.rb | 79 +++++++++ .../form/lettings/pages/referral_noms_spec.rb | 34 ---- .../referral_org_directly_referred_spec.rb | 71 ++++++++ .../pages/referral_org_nominated_spec.rb | 71 ++++++++ .../form/lettings/pages/referral_org_spec.rb | 34 ---- .../pages/referral_register_prp_spec.rb | 44 +++++ .../lettings/questions/referral_noms_spec.rb | 58 ++++-- .../lettings/questions/referral_org_spec.rb | 94 ++++++++-- .../questions/referral_register_spec.rb | 17 +- .../subsections/household_situation_spec.rb | 6 +- .../validations/household_validations_spec.rb | 166 ++++++++++++------ 12 files changed, 604 insertions(+), 149 deletions(-) create mode 100644 spec/models/form/lettings/pages/referral_noms_hr_spec.rb create mode 100644 spec/models/form/lettings/pages/referral_noms_la_hr_spec.rb delete mode 100644 spec/models/form/lettings/pages/referral_noms_spec.rb create mode 100644 spec/models/form/lettings/pages/referral_org_directly_referred_spec.rb create mode 100644 spec/models/form/lettings/pages/referral_org_nominated_spec.rb delete mode 100644 spec/models/form/lettings/pages/referral_org_spec.rb diff --git a/spec/models/form/lettings/pages/referral_noms_hr_spec.rb b/spec/models/form/lettings/pages/referral_noms_hr_spec.rb new file mode 100644 index 000000000..b3cd1e113 --- /dev/null +++ b/spec/models/form/lettings/pages/referral_noms_hr_spec.rb @@ -0,0 +1,79 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::ReferralNomsHr, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form:) } + let(:form) { instance_double(Form, start_date: Time.zone.today) } + let(:prp?) { nil } + let(:organisation) { instance_double(Organisation, prp?: prp?) } + let(:is_renewal?) { nil } + let(:referral_is_from_housing_register?) { nil } + let(:log) { instance_double(LettingsLog, is_renewal?: is_renewal?, owning_organisation: organisation, referral_is_from_housing_register?: referral_is_from_housing_register?) } + + before do + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[referral_noms]) + end + + it "has the correct id" do + expect(page.id).to eq("referral_noms_hr") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has the correct depends_on" do + expect(page.depends_on).to be nil + end + + context "and log owning organisation is not prp" do + let(:prp?) { false } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log owning organisation is prp" do + let(:prp?) { true } + + context "when log is a renewal" do + let(:is_renewal?) { true } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log is not a renewal" do + let(:is_renewal?) { false } + + context "and log referral is not from housing register" do + let(:referral_is_from_housing_register?) { false } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log referral is from housing register" do + let(:referral_is_from_housing_register?) { true } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + end + end +end diff --git a/spec/models/form/lettings/pages/referral_noms_la_hr_spec.rb b/spec/models/form/lettings/pages/referral_noms_la_hr_spec.rb new file mode 100644 index 000000000..91fb8cadb --- /dev/null +++ b/spec/models/form/lettings/pages/referral_noms_la_hr_spec.rb @@ -0,0 +1,79 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::ReferralNomsLaHr, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form:) } + let(:form) { instance_double(Form, start_date: Time.zone.today) } + let(:prp?) { nil } + let(:organisation) { instance_double(Organisation, prp?: prp?) } + let(:is_renewal?) { nil } + let(:referral_is_from_local_authority_housing_register?) { nil } + let(:log) { instance_double(LettingsLog, is_renewal?: is_renewal?, owning_organisation: organisation, referral_is_from_local_authority_housing_register?: referral_is_from_local_authority_housing_register?) } + + before do + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[referral_noms]) + end + + it "has the correct id" do + expect(page.id).to eq("referral_noms_la_hr") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has the correct depends_on" do + expect(page.depends_on).to be nil + end + + context "and log owning organisation is not prp" do + let(:prp?) { false } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log owning organisation is prp" do + let(:prp?) { true } + + context "when log is a renewal" do + let(:is_renewal?) { true } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log is not a renewal" do + let(:is_renewal?) { false } + + context "and log referral is not from local authority housing register" do + let(:referral_is_from_local_authority_housing_register?) { false } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log referral is from local authority housing register" do + let(:referral_is_from_local_authority_housing_register?) { true } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + end + end +end diff --git a/spec/models/form/lettings/pages/referral_noms_spec.rb b/spec/models/form/lettings/pages/referral_noms_spec.rb deleted file mode 100644 index 256e4fb4a..000000000 --- a/spec/models/form/lettings/pages/referral_noms_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Lettings::Pages::ReferralNoms, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } - - let(:page_id) { nil } - let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form:) } - let(:form) { instance_double(Form, start_date: Time.zone.today) } - - before do - allow(subsection).to receive(:form).and_return(form) - end - - it "has correct subsection" do - expect(page.subsection).to eq(subsection) - end - - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[referral_noms]) - end - - it "has the correct id" do - expect(page.id).to eq("referral_noms") - end - - it "has the correct description" do - expect(page.description).to be_nil - end - - it "has the correct depends_on" do - expect(page.depends_on).to be nil - end -end diff --git a/spec/models/form/lettings/pages/referral_org_directly_referred_spec.rb b/spec/models/form/lettings/pages/referral_org_directly_referred_spec.rb new file mode 100644 index 000000000..fc308aceb --- /dev/null +++ b/spec/models/form/lettings/pages/referral_org_directly_referred_spec.rb @@ -0,0 +1,71 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::ReferralOrgDirectlyReferred, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form:) } + let(:form) { instance_double(Form, start_date: Time.zone.today) } + let(:prp?) { nil } + let(:organisation) { instance_double(Organisation, prp?: prp?) } + let(:is_renewal?) { nil } + let(:referral_is_directly_referred?) { nil } + let(:log) { instance_double(LettingsLog, is_renewal?: is_renewal?, owning_organisation: organisation, referral_is_directly_referred?: referral_is_directly_referred?) } + + before do + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[referral_org]) + end + + it "has the correct id" do + expect(page.id).to eq("referral_org_directly_referred") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has the correct depends_on" do + expect(page.depends_on).to be nil + end + + context "and log owning organisation is prp" do + let(:prp?) { true } + + context "when log is a renewal" do + let(:is_renewal?) { true } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log is not a renewal" do + let(:is_renewal?) { false } + + context "and log referral is not nominated by local authority" do + let(:referral_is_directly_referred?) { false } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log referral is nominated by local authority" do + let(:referral_is_directly_referred?) { true } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + end + end +end diff --git a/spec/models/form/lettings/pages/referral_org_nominated_spec.rb b/spec/models/form/lettings/pages/referral_org_nominated_spec.rb new file mode 100644 index 000000000..1f0c0aab5 --- /dev/null +++ b/spec/models/form/lettings/pages/referral_org_nominated_spec.rb @@ -0,0 +1,71 @@ +require "rails_helper" + +RSpec.describe Form::Lettings::Pages::ReferralOrgNominated, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form:) } + let(:form) { instance_double(Form, start_date: Time.zone.today) } + let(:prp?) { nil } + let(:organisation) { instance_double(Organisation, prp?: prp?) } + let(:is_renewal?) { nil } + let(:referral_is_nominated_by_local_authority?) { nil } + let(:log) { instance_double(LettingsLog, is_renewal?: is_renewal?, owning_organisation: organisation, referral_is_nominated_by_local_authority?: referral_is_nominated_by_local_authority?) } + + before do + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[referral_org]) + end + + it "has the correct id" do + expect(page.id).to eq("referral_org_nominated") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has the correct depends_on" do + expect(page.depends_on).to be nil + end + + context "and log owning organisation is prp" do + let(:prp?) { true } + + context "when log is a renewal" do + let(:is_renewal?) { true } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log is not a renewal" do + let(:is_renewal?) { false } + + context "and log referral is not nominated by local authority" do + let(:referral_is_nominated_by_local_authority?) { false } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log referral is nominated by local authority" do + let(:referral_is_nominated_by_local_authority?) { true } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + end + end +end diff --git a/spec/models/form/lettings/pages/referral_org_spec.rb b/spec/models/form/lettings/pages/referral_org_spec.rb deleted file mode 100644 index cb39c95ca..000000000 --- a/spec/models/form/lettings/pages/referral_org_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "rails_helper" - -RSpec.describe Form::Lettings::Pages::ReferralOrg, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } - - let(:page_id) { nil } - let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection, form:) } - let(:form) { instance_double(Form, start_date: Time.zone.today) } - - before do - allow(subsection).to receive(:form).and_return(form) - end - - it "has correct subsection" do - expect(page.subsection).to eq(subsection) - end - - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[referral_org]) - end - - it "has the correct id" do - expect(page.id).to eq("referral_org") - end - - it "has the correct description" do - expect(page.description).to be_nil - end - - it "has the correct depends_on" do - expect(page.depends_on).to be nil - end -end diff --git a/spec/models/form/lettings/pages/referral_register_prp_spec.rb b/spec/models/form/lettings/pages/referral_register_prp_spec.rb index e62d54e47..bcb48562a 100644 --- a/spec/models/form/lettings/pages/referral_register_prp_spec.rb +++ b/spec/models/form/lettings/pages/referral_register_prp_spec.rb @@ -7,6 +7,10 @@ RSpec.describe Form::Lettings::Pages::ReferralRegisterPrp, type: :model do let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection, form:) } let(:form) { instance_double(Form, start_date: Time.zone.today) } + let(:prp?) { nil } + let(:organisation) { instance_double(Organisation, prp?: prp?) } + let(:is_renewal?) { nil } + let(:log) { instance_double(LettingsLog, is_renewal?: is_renewal?, owning_organisation: organisation) } before do allow(subsection).to receive(:form).and_return(form) @@ -31,4 +35,44 @@ RSpec.describe Form::Lettings::Pages::ReferralRegisterPrp, type: :model do it "has the correct depends_on" do expect(page.depends_on).to be nil end + + context "when log is a renewal" do + let(:is_renewal?) { true } + + context "and log owning organisation is prp" do + let(:prp?) { true } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + + context "and log owning organisation is not prp" do + let(:prp?) { false } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + end + + context "when log is not a renewal" do + let(:is_renewal?) { false } + + context "and log owning organisation is prp" do + let(:prp?) { true } + + it "is routed to" do + expect(page.routed_to?(log, nil)).to be true + end + end + + context "and log owning organisation is not prp" do + let(:prp?) { false } + + it "is not routed to" do + expect(page.routed_to?(log, nil)).to be false + end + end + end end diff --git a/spec/models/form/lettings/questions/referral_noms_spec.rb b/spec/models/form/lettings/questions/referral_noms_spec.rb index 064c4fbe7..23dd55b16 100644 --- a/spec/models/form/lettings/questions/referral_noms_spec.rb +++ b/spec/models/form/lettings/questions/referral_noms_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Lettings::Questions::ReferralNoms, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, referral_register) } let(:question_id) { nil } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:referral_register) { nil } let(:subsection) { instance_double(Form::Subsection) } let(:form) { instance_double(Form, start_date: Time.zone.today) } @@ -30,17 +31,50 @@ RSpec.describe Form::Lettings::Questions::ReferralNoms, type: :model do expect(question.derived?(nil)).to be false end - it "has the correct answer_options" do - expect(question.answer_options).to eq( - { - "1" => { - "value" => "Answer A", - }, - "2" => { - "value" => "Answer B", - }, - }.freeze, - ) + context "when referral_register is 6" do + let(:referral_register) { 6 } + + it "has the correct answer_options" do + expect(question.answer_options).to eq( + { + "1" => { + "value" => "Nominated by a local authority to a PRP", + }, + "2" => { + "value" => "Supported housing only - referred by a local authority to a PRP", + }, + "3" => { + "value" => "Internal transfer from another property owned by the same PRP landlord - for existing social tenants only", + }, + "4" => { + "value" => "Other", + }, + }.freeze, + ) + end + end + + context "when referral_register is 7" do + let(:referral_register) { 7 } + + it "has the correct answer_options" do + expect(question.answer_options).to eq( + { + "5" => { + "value" => "Internal transfer from another property owned by the same PRP landlord - for existing social tenants only", + }, + "6" => { + "value" => " A different PRP landlord - for existing socail tenants only", + }, + "7" => { + "value" => "Directly referred by a third party", + }, + "8" => { + "value" => "Other", + }, + }.freeze, + ) + end end it "has the correct question_number" do diff --git a/spec/models/form/lettings/questions/referral_org_spec.rb b/spec/models/form/lettings/questions/referral_org_spec.rb index 0c01d972b..b407ea796 100644 --- a/spec/models/form/lettings/questions/referral_org_spec.rb +++ b/spec/models/form/lettings/questions/referral_org_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Lettings::Questions::ReferralOrg, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, referral_noms) } let(:question_id) { nil } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:referral_noms) { nil } let(:subsection) { instance_double(Form::Subsection) } let(:form) { instance_double(Form, start_date: Time.zone.today) } @@ -30,17 +31,86 @@ RSpec.describe Form::Lettings::Questions::ReferralOrg, type: :model do expect(question.derived?(nil)).to be false end - it "has the correct answer_options" do - expect(question.answer_options).to eq( - { - "1" => { - "value" => "Answer A", - }, - "2" => { - "value" => "Answer B", - }, - }.freeze, - ) + context "when referral_noms is 1" do + let(:referral_noms) { 1 } + + it "has the correct answer_options" do + expect(question.answer_options).to eq( + { + "1" => { + "value" => "Referred to LA by health service", + }, + "2" => { + "value" => "Referred to LA by community learning disability team", + }, + "3" => { + "value" => "Referred to LA by community mental health team", + }, + "4" => { + "value" => "Referred to LA by adult social services", + }, + "5" => { + "value" => "Referred to LA by children's social care", + }, + "6" => { + "value" => "Referred to LA by police, probation, prison or youth offending team following a custodial sentence", + }, + "7" => { + "value" => "Referred to LA by police, probation, prison or youth offending team without a custodial sentence", + }, + "8" => { + "value" => "Referred to LA by a voluntary agency", + }, + "9" => { + "value" => "Other referral", + }, + "10" => { + "value" => "Don't know", + }, + }.freeze, + ) + end + end + + context "when referral_noms is 7" do + let(:referral_noms) { 7 } + + it "has the correct answer_options" do + expect(question.answer_options).to eq( + { + "11" => { + "value" => "Health service", + }, + "12" => { + "value" => "Community learning disability team", + }, + "13" => { + "value" => "Community mental health team", + }, + "14" => { + "value" => "Adult social services", + }, + "15" => { + "value" => "Children's social care", + }, + "16" => { + "value" => "Police, probation, prison or youth offending team following a custodial sentence", + }, + "17" => { + "value" => "Police, probation, prison or youth offending team without a custodial sentence", + }, + "18" => { + "value" => "Voluntary agency", + }, + "19" => { + "value" => "Other third party", + }, + "20" => { + "value" => "Don't know", + }, + }.freeze, + ) + end end it "has the correct question_number" do diff --git a/spec/models/form/lettings/questions/referral_register_spec.rb b/spec/models/form/lettings/questions/referral_register_spec.rb index 112de43e0..4cf53cd23 100644 --- a/spec/models/form/lettings/questions/referral_register_spec.rb +++ b/spec/models/form/lettings/questions/referral_register_spec.rb @@ -74,11 +74,20 @@ RSpec.describe Form::Lettings::Questions::ReferralRegister, type: :model do it "has the correct answer_options" do expect(question.answer_options).to eq( { - "1" => { - "value" => "Answer A", + "5" => { + "value" => "Renewal to the same tenant in the same property", }, - "2" => { - "value" => "Answer B", + "6" => { + "value" => "From a local authority housing register (waiting list) or a register with local authority involvement", + }, + "7" => { + "value" => "From a housing register (waiting list) with no local authority involvement", + }, + "8" => { + "value" => "Tenant applied directly (not via a nomination or waiting list)", + }, + "9" => { + "value" => "Don't know", }, }.freeze, ) diff --git a/spec/models/form/lettings/subsections/household_situation_spec.rb b/spec/models/form/lettings/subsections/household_situation_spec.rb index 909046719..3da63a140 100644 --- a/spec/models/form/lettings/subsections/household_situation_spec.rb +++ b/spec/models/form/lettings/subsections/household_situation_spec.rb @@ -109,8 +109,10 @@ RSpec.describe Form::Lettings::Subsections::HouseholdSituation, type: :model do allocation_system referral_register_la referral_register_prp - referral_noms - referral_org + referral_noms_la_hr + referral_noms_hr + referral_org_nominated + referral_org_directly_referred ], ) end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 78f27ed3f..2ccf89af6 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -491,68 +491,132 @@ RSpec.describe Validations::HouseholdValidations do end end - context "when start year is 2026 and record is internal transfer and owning organisation is LA" do + context "when start year is 2026" do let(:startdate) { collection_start_date_for_year(2026) } - before do - record.owning_organisation.provider_type = "LA" - record.referral_register = 2 - end + context "and record is internal transfer via LA path" do + before do + record.owning_organisation.provider_type = "LA" + record.referral_register = 2 + end - [ - { code: 3, label: "Private sector tenancy" }, - { code: 27, label: "Owner occupation (low-cost home ownership)" }, - { code: 26, label: "Owner occupation (private)" }, - { code: 28, label: "Living with friends or family (long-term)" }, - { code: 39, label: "Sofa surfing (moving regularly between family or friends, no permanent bed)" }, - { code: 14, label: "Bed and breakfast" }, - { code: 7, label: "Direct access hostel" }, - { code: 10, label: "Hospital" }, - { code: 29, label: "Prison or approved probation hostel" }, - { code: 19, label: "Rough sleeping" }, - { code: 18, label: "Any other temporary accommodation" }, - { code: 13, label: "Children’s home or foster care" }, - { code: 24, label: "Home Office Asylum Support" }, - { code: 37, label: "Host family or similar refugee accommodation" }, - { code: 23, label: "Mobile home or caravan" }, - { code: 21, label: "Refuge" }, - { code: 9, label: "Residential care home" }, - { code: 4, label: "Tied housing or rented with job" }, - { code: 25, label: "Any other accommodation" }, - ].each do |prevten| - context "and prevten is #{prevten[:code]}" do - before do - record.prevten = prevten[:code] + [ + { code: 3, label: "Private sector tenancy" }, + { code: 27, label: "Owner occupation (low-cost home ownership)" }, + { code: 26, label: "Owner occupation (private)" }, + { code: 28, label: "Living with friends or family (long-term)" }, + { code: 39, label: "Sofa surfing (moving regularly between family or friends, no permanent bed)" }, + { code: 14, label: "Bed and breakfast" }, + { code: 7, label: "Direct access hostel" }, + { code: 10, label: "Hospital" }, + { code: 29, label: "Prison or approved probation hostel" }, + { code: 19, label: "Rough sleeping" }, + { code: 18, label: "Any other temporary accommodation" }, + { code: 13, label: "Children’s home or foster care" }, + { code: 24, label: "Home Office Asylum Support" }, + { code: 37, label: "Host family or similar refugee accommodation" }, + { code: 23, label: "Mobile home or caravan" }, + { code: 21, label: "Refuge" }, + { code: 9, label: "Residential care home" }, + { code: 4, label: "Tied housing or rented with job" }, + { code: 25, label: "Any other accommodation" }, + ].each do |prevten| + context "and prevten is #{prevten[:code]}" do + it "adds an error" do + record.referral_register = 2 + record.prevten = prevten[:code] + household_validator.validate_referral(record) + expect(record.errors["prevten"]) + .to include(match I18n.t("validations.lettings.household.prevten.general_needs.internal_transfer", prevten: prevten[:label])) + expect(record.errors["referral_register"]) + .to include(match I18n.t("validations.lettings.household.referral.general_needs.internal_transfer", prevten: prevten[:label])) + end end + end - it "adds an error" do - household_validator.validate_referral(record) - expect(record.errors["prevten"]) - .to include(match I18n.t("validations.lettings.household.prevten.general_needs.internal_transfer", prevten: prevten[:label])) - expect(record.errors["referral_register"]) - .to include(match I18n.t("validations.lettings.household.referral.general_needs.internal_transfer", prevten: prevten[:label])) + [ + { code: 30, label: "Fixed-term local authority general needs tenancy" }, + { code: 31, label: "Lifetime local authority general needs tenancy" }, + { code: 32, label: "Fixed-term private registered provider (PRP) general needs tenancy" }, + { code: 33, label: "Lifetime private registered provider (PRP) general needs tenancy" }, + { code: 35, label: "Extra care housing" }, + { code: 38, label: "Older people’s housing for tenants with low support needs" }, + { code: 6, label: "Other supported housing" }, + ].each do |prevten| + context "and prevten is #{prevten[:code]}" do + before do + record.prevten = prevten[:code] + end + + it "does not add an error" do + household_validator.validate_referral(record) + expect(record.errors["prevten"]).to be_empty + expect(record.errors["referral"]).to be_empty + end end end end - [ - { code: 30, label: "Fixed-term local authority general needs tenancy" }, - { code: 31, label: "Lifetime local authority general needs tenancy" }, - { code: 32, label: "Fixed-term private registered provider (PRP) general needs tenancy" }, - { code: 33, label: "Lifetime private registered provider (PRP) general needs tenancy" }, - { code: 35, label: "Extra care housing" }, - { code: 38, label: "Older people’s housing for tenants with low support needs" }, - { code: 6, label: "Other supported housing" }, - ].each do |prevten| - context "and prevten is #{prevten[:code]}" do - before do - record.prevten = prevten[:code] + context "and record is internal transfer via PRP path" do + before do + record.owning_organisation.provider_type = "PRP" + record.referral_register = 6 + record.referral_noms = 3 + end + + [ + { code: 3, label: "Private sector tenancy" }, + { code: 27, label: "Owner occupation (low-cost home ownership)" }, + { code: 26, label: "Owner occupation (private)" }, + { code: 28, label: "Living with friends or family (long-term)" }, + { code: 39, label: "Sofa surfing (moving regularly between family or friends, no permanent bed)" }, + { code: 14, label: "Bed and breakfast" }, + { code: 7, label: "Direct access hostel" }, + { code: 10, label: "Hospital" }, + { code: 29, label: "Prison or approved probation hostel" }, + { code: 19, label: "Rough sleeping" }, + { code: 18, label: "Any other temporary accommodation" }, + { code: 13, label: "Children’s home or foster care" }, + { code: 24, label: "Home Office Asylum Support" }, + { code: 37, label: "Host family or similar refugee accommodation" }, + { code: 23, label: "Mobile home or caravan" }, + { code: 21, label: "Refuge" }, + { code: 9, label: "Residential care home" }, + { code: 4, label: "Tied housing or rented with job" }, + { code: 25, label: "Any other accommodation" }, + ].each do |prevten| + context "and prevten is #{prevten[:code]}" do + it "adds an error" do + record.referral_register = 2 + record.prevten = prevten[:code] + household_validator.validate_referral(record) + expect(record.errors["prevten"]) + .to include(match I18n.t("validations.lettings.household.prevten.general_needs.internal_transfer", prevten: prevten[:label])) + expect(record.errors["referral_register"]) + .to include(match I18n.t("validations.lettings.household.referral.general_needs.internal_transfer", prevten: prevten[:label])) + end end + end - it "does not add an error" do - household_validator.validate_referral(record) - expect(record.errors["prevten"]).to be_empty - expect(record.errors["referral"]).to be_empty + [ + { code: 30, label: "Fixed-term local authority general needs tenancy" }, + { code: 31, label: "Lifetime local authority general needs tenancy" }, + { code: 32, label: "Fixed-term private registered provider (PRP) general needs tenancy" }, + { code: 33, label: "Lifetime private registered provider (PRP) general needs tenancy" }, + { code: 35, label: "Extra care housing" }, + { code: 38, label: "Older people’s housing for tenants with low support needs" }, + { code: 6, label: "Other supported housing" }, + ].each do |prevten| + context "and prevten is #{prevten[:code]}" do + before do + record.prevten = prevten[:code] + end + + it "does not add an error" do + household_validator.validate_referral(record) + expect(record.errors["prevten"]).to be_empty + expect(record.errors["referral"]).to be_empty + end end end end