Browse Source

Update unitletas mapping for 23/24 forms

pull/1303/head
Kat 3 years ago
parent
commit
f289fea5bd
  1. 11
      app/models/derived_variables/lettings_log_variables.rb
  2. 55
      spec/models/lettings_log_spec.rb

11
app/models/derived_variables/lettings_log_variables.rb

@ -18,6 +18,15 @@ module DerivedVariables::LettingsLogVariables
5 => 4, # "Other intermediate rent product" => "Intermediate Rent basis"
}.freeze
UNITLETAS_MAPPING_23_24 = {
0 => 1, # "Social Rent" => "Social Rent basis"
1 => 2, # "Affordable Rent" => "Affordable Rent basis"
2 => 5, # "London Affordable Rent" => "London Affordable Rent basis"
3 => 6, # "Rent to Buy" => "Rent to Buy basis"
4 => 7, # "London Living Rent" => "London Living Rent basis"
5 => 8, # "Other intermediate rent product" => "Another Intermediate Rent basis"
}.freeze
def scheme_has_multiple_locations?
return false unless scheme
@ -66,7 +75,7 @@ module DerivedVariables::LettingsLogVariables
self.voiddate = startdate
self.first_time_property_let_as_social_housing = 0
self.rsnvac = 14
self.unitletas = UNITLETAS_MAPPING[rent_type]
self.unitletas = form.start_date.year >= 2023 ? UNITLETAS_MAPPING_23_24[rent_type] : UNITLETAS_MAPPING[rent_type]
if is_general_needs?
# fixed term
self.prevten = 32 if managing_organisation&.provider_type == "PRP"

55
spec/models/lettings_log_spec.rb

@ -1477,6 +1477,7 @@ RSpec.describe LettingsLog do
context "when deriving renttype and unitletas" do
before do
allow(FeatureToggle).to receive(:startdate_two_week_validation_enabled?).and_return(false)
lettings_log.update!(rent_type:, irproduct_other: "other")
end
@ -1494,6 +1495,15 @@ RSpec.describe LettingsLog do
expect(lettings_log.unitletas).to eq(1)
expect(record_from_db["unitletas"]).to eq(1)
end
context "and it is a 23/24 form" do
it "derives and saves unitletas as Social rent(1)" do
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1))
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.unitletas).to eq(1)
expect(record_from_db["unitletas"]).to eq(1)
end
end
end
context "when the rent_type is Affordable Rent(1)" do
@ -1510,6 +1520,15 @@ RSpec.describe LettingsLog do
expect(lettings_log.unitletas).to eq(2)
expect(record_from_db["unitletas"]).to eq(2)
end
context "and it is a 23/24 form" do
it "derives and saves unitletas as Affordable Rent basis(2)" do
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1))
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.unitletas).to eq(2)
expect(record_from_db["unitletas"]).to eq(2)
end
end
end
context "when the rent_type is London Affordable Rent(2)" do
@ -1526,6 +1545,15 @@ RSpec.describe LettingsLog do
expect(lettings_log.unitletas).to eq(2)
expect(record_from_db["unitletas"]).to eq(2)
end
context "and it is a 23/24 form" do
it "derives and saves unitletas as London Affordable Rent basis(5)" do
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1))
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.unitletas).to eq(5)
expect(record_from_db["unitletas"]).to eq(5)
end
end
end
context "when the rent_type is Rent to Buy(3)" do
@ -1542,6 +1570,15 @@ RSpec.describe LettingsLog do
expect(lettings_log.unitletas).to eq(4)
expect(record_from_db["unitletas"]).to eq(4)
end
context "and it is a 23/24 form" do
it "derives and saves unitletas as Rent to Buy basis(6)" do
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1))
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.unitletas).to eq(6)
expect(record_from_db["unitletas"]).to eq(6)
end
end
end
context "when the rent_type is London Living Rent(4)" do
@ -1558,6 +1595,15 @@ RSpec.describe LettingsLog do
expect(lettings_log.unitletas).to eq(4)
expect(record_from_db["unitletas"]).to eq(4)
end
context "and it is a 23/24 form" do
it "derives and saves unitletas as London Living Rent basis(7)" do
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1))
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.unitletas).to eq(7)
expect(record_from_db["unitletas"]).to eq(7)
end
end
end
context "when the rent_type is Other intermediate rent product(5)" do
@ -1574,6 +1620,15 @@ RSpec.describe LettingsLog do
expect(lettings_log.unitletas).to eq(4)
expect(record_from_db["unitletas"]).to eq(4)
end
context "and it is a 23/24 form" do
it "derives and saves unitletas as Other intermediate rent basis(8)" do
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1))
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0]
expect(lettings_log.unitletas).to eq(8)
expect(record_from_db["unitletas"]).to eq(8)
end
end
end
end
end

Loading…
Cancel
Save