Browse Source

CLDC-4189: Add tests

CLDC-4151-new-referral-questions
Samuel Young 3 weeks ago
parent
commit
bef2ff343f
  1. 79
      spec/models/form/lettings/pages/referral_noms_hr_spec.rb
  2. 79
      spec/models/form/lettings/pages/referral_noms_la_hr_spec.rb
  3. 34
      spec/models/form/lettings/pages/referral_noms_spec.rb
  4. 71
      spec/models/form/lettings/pages/referral_org_directly_referred_spec.rb
  5. 71
      spec/models/form/lettings/pages/referral_org_nominated_spec.rb
  6. 34
      spec/models/form/lettings/pages/referral_org_spec.rb
  7. 44
      spec/models/form/lettings/pages/referral_register_prp_spec.rb
  8. 40
      spec/models/form/lettings/questions/referral_noms_spec.rb
  9. 76
      spec/models/form/lettings/questions/referral_org_spec.rb
  10. 17
      spec/models/form/lettings/questions/referral_register_spec.rb
  11. 6
      spec/models/form/lettings/subsections/household_situation_spec.rb
  12. 66
      spec/models/validations/household_validations_spec.rb

79
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

79
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

34
spec/models/form/lettings/pages/referral_noms_spec.rb

@ -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

71
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

71
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

34
spec/models/form/lettings/pages/referral_org_spec.rb

@ -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

44
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(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form:) } let(:subsection) { instance_double(Form::Subsection, form:) }
let(:form) { instance_double(Form, start_date: Time.zone.today) } 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 before do
allow(subsection).to receive(:form).and_return(form) 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 it "has the correct depends_on" do
expect(page.depends_on).to be nil expect(page.depends_on).to be nil
end 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 end

40
spec/models/form/lettings/questions/referral_noms_spec.rb

@ -1,11 +1,12 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Lettings::Questions::ReferralNoms, type: :model do 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_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:referral_register) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.today) } let(:form) { instance_double(Form, start_date: Time.zone.today) }
@ -30,18 +31,51 @@ RSpec.describe Form::Lettings::Questions::ReferralNoms, type: :model do
expect(question.derived?(nil)).to be false expect(question.derived?(nil)).to be false
end end
context "when referral_register is 6" do
let(:referral_register) { 6 }
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options).to eq( expect(question.answer_options).to eq(
{ {
"1" => { "1" => {
"value" => "Answer A", "value" => "Nominated by a local authority to a PRP",
}, },
"2" => { "2" => {
"value" => "Answer B", "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, }.freeze,
) )
end 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 it "has the correct question_number" do
expect(question.question_number).to eq(84) expect(question.question_number).to eq(84)

76
spec/models/form/lettings/questions/referral_org_spec.rb

@ -1,11 +1,12 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Lettings::Questions::ReferralOrg, type: :model do 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_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:referral_noms) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: Time.zone.today) } let(:form) { instance_double(Form, start_date: Time.zone.today) }
@ -30,18 +31,87 @@ RSpec.describe Form::Lettings::Questions::ReferralOrg, type: :model do
expect(question.derived?(nil)).to be false expect(question.derived?(nil)).to be false
end end
context "when referral_noms is 1" do
let(:referral_noms) { 1 }
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options).to eq( expect(question.answer_options).to eq(
{ {
"1" => { "1" => {
"value" => "Answer A", "value" => "Referred to LA by health service",
}, },
"2" => { "2" => {
"value" => "Answer B", "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, }.freeze,
) )
end 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 it "has the correct question_number" do
expect(question.question_number).to eq(84) expect(question.question_number).to eq(84)

17
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 it "has the correct answer_options" do
expect(question.answer_options).to eq( expect(question.answer_options).to eq(
{ {
"1" => { "5" => {
"value" => "Answer A", "value" => "Renewal to the same tenant in the same property",
}, },
"2" => { "6" => {
"value" => "Answer B", "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, }.freeze,
) )

6
spec/models/form/lettings/subsections/household_situation_spec.rb

@ -109,8 +109,10 @@ RSpec.describe Form::Lettings::Subsections::HouseholdSituation, type: :model do
allocation_system allocation_system
referral_register_la referral_register_la
referral_register_prp referral_register_prp
referral_noms referral_noms_la_hr
referral_org referral_noms_hr
referral_org_nominated
referral_org_directly_referred
], ],
) )
end end

66
spec/models/validations/household_validations_spec.rb

@ -491,9 +491,10 @@ RSpec.describe Validations::HouseholdValidations do
end end
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) } let(:startdate) { collection_start_date_for_year(2026) }
context "and record is internal transfer via LA path" do
before do before do
record.owning_organisation.provider_type = "LA" record.owning_organisation.provider_type = "LA"
record.referral_register = 2 record.referral_register = 2
@ -519,13 +520,75 @@ RSpec.describe Validations::HouseholdValidations do
{ code: 9, label: "Residential care home" }, { code: 9, label: "Residential care home" },
{ code: 4, label: "Tied housing or rented with job" }, { code: 4, label: "Tied housing or rented with job" },
{ code: 25, label: "Any other accommodation" }, { 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
[
{ 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| ].each do |prevten|
context "and prevten is #{prevten[:code]}" do context "and prevten is #{prevten[:code]}" do
before do before do
record.prevten = prevten[:code] record.prevten = prevten[:code]
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
end
end
end
end
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 it "adds an error" do
record.referral_register = 2
record.prevten = prevten[:code]
household_validator.validate_referral(record) household_validator.validate_referral(record)
expect(record.errors["prevten"]) expect(record.errors["prevten"])
.to include(match I18n.t("validations.lettings.household.prevten.general_needs.internal_transfer", prevten: prevten[:label])) .to include(match I18n.t("validations.lettings.household.prevten.general_needs.internal_transfer", prevten: prevten[:label]))
@ -558,6 +621,7 @@ RSpec.describe Validations::HouseholdValidations do
end end
end end
end end
end
describe "la validations" do describe "la validations" do
context "when previous la is known" do context "when previous la is known" do

Loading…
Cancel
Save