Browse Source

CLDC-3305 Update previous postcode routing for renewals (#2325)

* Derive previous postcode for renewals

* Do not route renewals to previous postcode

* Update test
pull/2352/head^2
kosiakkatrina 9 months ago committed by GitHub
parent
commit
826b803e4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      app/models/derived_variables/lettings_log_variables.rb
  2. 2
      app/models/form/lettings/pages/previous_local_authority.rb
  3. 5
      app/models/form/lettings/pages/previous_postcode.rb
  4. 1
      spec/features/form/accessible_autocomplete_spec.rb
  5. 38
      spec/models/form/lettings/pages/previous_local_authority_spec.rb
  6. 38
      spec/models/form/lettings/pages/previous_postcode_spec.rb
  7. 9
      spec/models/lettings_log_spec.rb

10
app/models/derived_variables/lettings_log_variables.rb

@ -90,6 +90,16 @@ module DerivedVariables::LettingsLogVariables
self.prevten = 32 if owning_organisation&.provider_type == "PRP" self.prevten = 32 if owning_organisation&.provider_type == "PRP"
self.prevten = 30 if owning_organisation&.provider_type == "LA" self.prevten = 30 if owning_organisation&.provider_type == "LA"
end end
self.ppostcode_full = postcode_full
self.ppcodenk = case postcode_known
when 0
1
when 1
0
end
self.is_previous_la_inferred = is_la_inferred
self.previous_la_known = 1 if la.present?
self.prevloc = la
end end
if form.start_year_after_2024? && is_bedsit? if form.start_year_after_2024? && is_bedsit?
self.beds = 1 self.beds = 1

2
app/models/form/lettings/pages/previous_local_authority.rb

@ -2,7 +2,7 @@ class Form::Lettings::Pages::PreviousLocalAuthority < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "previous_local_authority" @id = "previous_local_authority"
@depends_on = [{ "is_previous_la_inferred" => false }] @depends_on = [{ "is_previous_la_inferred" => false, "renewal" => 0 }]
end end
def questions def questions

5
app/models/form/lettings/pages/previous_postcode.rb

@ -1,4 +1,9 @@
class Form::Lettings::Pages::PreviousPostcode < ::Form::Page class Form::Lettings::Pages::PreviousPostcode < ::Form::Page
def initialize(id, hsh, page)
super
@depends_on = [{ "renewal" => 0 }]
end
def questions def questions
@questions ||= [ @questions ||= [
Form::Lettings::Questions::Ppcodenk.new(nil, nil, self), Form::Lettings::Questions::Ppcodenk.new(nil, nil, self),

1
spec/features/form/accessible_autocomplete_spec.rb

@ -17,6 +17,7 @@ RSpec.describe "Accessible Autocomplete" do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
renewal: 0,
previous_la_known: 1, previous_la_known: 1,
prevloc: "E09000033", prevloc: "E09000033",
illness: 1, illness: 1,

38
spec/models/form/lettings/pages/previous_local_authority_spec.rb

@ -0,0 +1,38 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::PreviousLocalAuthority, 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: instance_double(Form, start_year_after_2024?: false, start_date: Time.zone.local(2023, 4, 1))) }
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[
previous_la_known
prevloc
],
)
end
it "has the correct id" do
expect(page.id).to eq("previous_local_authority")
end
it "has the correct header" do
expect(page.header).to be_nil
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 match([{ "is_previous_la_inferred" => false, "renewal" => 0 }])
end
end

38
spec/models/form/lettings/pages/previous_postcode_spec.rb

@ -0,0 +1,38 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::PreviousPostcode, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "previous_postcode" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_year_after_2024?: false, start_date: Time.zone.local(2023, 4, 1))) }
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[
ppcodenk
ppostcode_full
],
)
end
it "has the correct id" do
expect(page.id).to eq("previous_postcode")
end
it "has the correct header" do
expect(page.header).to be_nil
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 match([{ "renewal" => 0 }])
end
end

9
spec/models/lettings_log_spec.rb

@ -1592,6 +1592,15 @@ RSpec.describe LettingsLog do
expect { lettings_log.update!(startdate: Time.zone.local(2023, 4, 1)) }.to change(lettings_log, :underoccupation_benefitcap).from(2).to nil expect { lettings_log.update!(startdate: Time.zone.local(2023, 4, 1)) }.to change(lettings_log, :underoccupation_benefitcap).from(2).to nil
end end
it "derives ppostcode_full as postcode_full if log is renewal" do
lettings_log.update!(renewal: 0, postcode_full: "M1 1AE", postcode_known: 1, ppostcode_full: "M1 1AD")
lettings_log.update!(renewal: 1)
lettings_log.reload
expect(lettings_log.ppostcode_full).to eq("M1 1AE")
expect(lettings_log.ppcodenk).to eq(0)
expect(lettings_log.prevloc).to eq(lettings_log.la)
end
context "when the log is general needs" do context "when the log is general needs" do
context "and the managing organisation is a private registered provider" do context "and the managing organisation is a private registered provider" do
before do before do

Loading…
Cancel
Save