|
|
|
@ -6,14 +6,19 @@ RSpec.describe LettingsLog do |
|
|
|
let(:created_by_user) { FactoryBot.create(:user) } |
|
|
|
let(:created_by_user) { FactoryBot.create(:user) } |
|
|
|
let(:owning_organisation) { created_by_user.organisation } |
|
|
|
let(:owning_organisation) { created_by_user.organisation } |
|
|
|
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } |
|
|
|
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } |
|
|
|
|
|
|
|
let(:fake_2022_2023_form) { Form.new("spec/fixtures/forms/2022_2023.json") } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
around do |example| |
|
|
|
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) |
|
|
|
Timecop.freeze(Time.utc(2022, 1, 1)) do |
|
|
|
Timecop.freeze(Time.zone.local(2022, 1, 1)) |
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
before do |
|
|
|
Timecop.unfreeze |
|
|
|
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
include_examples "shared examples for derived fields", :lettings_log |
|
|
|
include_examples "shared examples for derived fields", :lettings_log |
|
|
|
@ -38,7 +43,15 @@ RSpec.describe LettingsLog do |
|
|
|
let(:lettings_log_2) { FactoryBot.build(:lettings_log, startdate: Time.zone.local(2022, 1, 1), created_by: created_by_user) } |
|
|
|
let(:lettings_log_2) { FactoryBot.build(:lettings_log, startdate: Time.zone.local(2022, 1, 1), created_by: created_by_user) } |
|
|
|
let(:lettings_log_year_2) { FactoryBot.build(:lettings_log, startdate: Time.zone.local(2023, 5, 1), created_by: created_by_user) } |
|
|
|
let(:lettings_log_year_2) { FactoryBot.build(:lettings_log, startdate: Time.zone.local(2023, 5, 1), created_by: created_by_user) } |
|
|
|
|
|
|
|
|
|
|
|
it "has returns the correct form based on the start date" do |
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(2023, 1, 1) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns the correct form based on the start date" do |
|
|
|
expect(lettings_log.form_name).to be_nil |
|
|
|
expect(lettings_log.form_name).to be_nil |
|
|
|
expect(lettings_log.form).to be_a(Form) |
|
|
|
expect(lettings_log.form).to be_a(Form) |
|
|
|
expect(lettings_log_2.form_name).to eq("previous_lettings") |
|
|
|
expect(lettings_log_2.form_name).to eq("previous_lettings") |
|
|
|
@ -1482,10 +1495,15 @@ RSpec.describe LettingsLog do |
|
|
|
|
|
|
|
|
|
|
|
context "when deriving renttype and unitletas" do |
|
|
|
context "when deriving renttype and unitletas" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2022, 1, 1)) |
|
|
|
allow(FeatureToggle).to receive(:startdate_two_week_validation_enabled?).and_return(false) |
|
|
|
allow(FeatureToggle).to receive(:startdate_two_week_validation_enabled?).and_return(false) |
|
|
|
lettings_log.update!(rent_type:, irproduct_other: "other") |
|
|
|
lettings_log.update!(rent_type:, irproduct_other: "other") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when the rent_type is Social Rent (0)" do |
|
|
|
context "when the rent_type is Social Rent (0)" do |
|
|
|
let(:rent_type) { 0 } |
|
|
|
let(:rent_type) { 0 } |
|
|
|
|
|
|
|
|
|
|
|
@ -1502,6 +1520,23 @@ RSpec.describe LettingsLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and it is a 23/24 form" do |
|
|
|
context "and it is a 23/24 form" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) do |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "derives and saves unitletas as Social rent(1)" do |
|
|
|
it "derives and saves unitletas as Social rent(1)" do |
|
|
|
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1)) |
|
|
|
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] |
|
|
|
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0] |
|
|
|
@ -1527,6 +1562,23 @@ RSpec.describe LettingsLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and it is a 23/24 form" do |
|
|
|
context "and it is a 23/24 form" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) do |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "derives and saves unitletas as Affordable Rent basis(2)" do |
|
|
|
it "derives and saves unitletas as Affordable Rent basis(2)" do |
|
|
|
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1)) |
|
|
|
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] |
|
|
|
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0] |
|
|
|
@ -1552,6 +1604,23 @@ RSpec.describe LettingsLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and it is a 23/24 form" do |
|
|
|
context "and it is a 23/24 form" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) do |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "derives and saves unitletas as London Affordable Rent basis(5)" do |
|
|
|
it "derives and saves unitletas as London Affordable Rent basis(5)" do |
|
|
|
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1)) |
|
|
|
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] |
|
|
|
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0] |
|
|
|
@ -1577,6 +1646,23 @@ RSpec.describe LettingsLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and it is a 23/24 form" do |
|
|
|
context "and it is a 23/24 form" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) do |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "derives and saves unitletas as Rent to Buy basis(6)" do |
|
|
|
it "derives and saves unitletas as Rent to Buy basis(6)" do |
|
|
|
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1)) |
|
|
|
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] |
|
|
|
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0] |
|
|
|
@ -1602,6 +1688,23 @@ RSpec.describe LettingsLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and it is a 23/24 form" do |
|
|
|
context "and it is a 23/24 form" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) do |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "derives and saves unitletas as London Living Rent basis(7)" do |
|
|
|
it "derives and saves unitletas as London Living Rent basis(7)" do |
|
|
|
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1)) |
|
|
|
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] |
|
|
|
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0] |
|
|
|
@ -1627,6 +1730,23 @@ RSpec.describe LettingsLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and it is a 23/24 form" do |
|
|
|
context "and it is a 23/24 form" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 5, 1)) do |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "derives and saves unitletas as Other intermediate rent basis(8)" do |
|
|
|
it "derives and saves unitletas as Other intermediate rent basis(8)" do |
|
|
|
lettings_log.update!(startdate: Time.zone.local(2023, 5, 1)) |
|
|
|
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] |
|
|
|
record_from_db = ActiveRecord::Base.connection.execute("select unitletas from lettings_logs where id=#{lettings_log.id}").to_a[0] |
|
|
|
@ -1865,6 +1985,14 @@ RSpec.describe LettingsLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and a scheme with a single log is selected" do |
|
|
|
context "and a scheme with a single log is selected" do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(2022, 4, 2) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
let(:scheme) { FactoryBot.create(:scheme) } |
|
|
|
let(:scheme) { FactoryBot.create(:scheme) } |
|
|
|
let!(:location) { FactoryBot.create(:location, scheme:) } |
|
|
|
let!(:location) { FactoryBot.create(:location, scheme:) } |
|
|
|
|
|
|
|
|
|
|
|
@ -1922,8 +2050,6 @@ RSpec.describe LettingsLog do |
|
|
|
|
|
|
|
|
|
|
|
context "and renewal" do |
|
|
|
context "and renewal" do |
|
|
|
let(:scheme) { FactoryBot.create(:scheme) } |
|
|
|
let(:scheme) { FactoryBot.create(:scheme) } |
|
|
|
let(:location) { FactoryBot.create(:location, scheme:) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let!(:supported_housing_lettings_log) do |
|
|
|
let!(:supported_housing_lettings_log) do |
|
|
|
described_class.create!({ |
|
|
|
described_class.create!({ |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
managing_organisation: owning_organisation, |
|
|
|
@ -1937,8 +2063,17 @@ RSpec.describe LettingsLog do |
|
|
|
created_at: Time.utc(2022, 2, 8, 16, 52, 15), |
|
|
|
created_at: Time.utc(2022, 2, 8, 16, 52, 15), |
|
|
|
}) |
|
|
|
}) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
let(:location) { FactoryBot.create(:location, scheme:) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Timecop.freeze(2022, 4, 2) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "correcly infers and saves the renewal date" do |
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "correctly infers and saves the renewal date" do |
|
|
|
record_from_db = ActiveRecord::Base.connection.execute("SELECT voiddate from lettings_logs where id=#{supported_housing_lettings_log.id}").to_a[0] |
|
|
|
record_from_db = ActiveRecord::Base.connection.execute("SELECT voiddate from lettings_logs where id=#{supported_housing_lettings_log.id}").to_a[0] |
|
|
|
expect(record_from_db["voiddate"].to_i).to eq(supported_housing_lettings_log.startdate.to_i) |
|
|
|
expect(record_from_db["voiddate"].to_i).to eq(supported_housing_lettings_log.startdate.to_i) |
|
|
|
end |
|
|
|
end |
|
|
|
@ -2275,6 +2410,15 @@ RSpec.describe LettingsLog do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "and the new location triggers the rent range validation" do |
|
|
|
context "and the new location triggers the rent range validation" do |
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
|
|
|
Timecop.freeze(Time.zone.local(2022, 4, 1)) do |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
example.run |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Timecop.return |
|
|
|
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "clears rent values" do |
|
|
|
it "clears rent values" do |
|
|
|
lettings_log.update!(location:, scheme:) |
|
|
|
lettings_log.update!(location:, scheme:) |
|
|
|
lettings_log.reload |
|
|
|
lettings_log.reload |
|
|
|
@ -2691,8 +2835,7 @@ RSpec.describe LettingsLog do |
|
|
|
let(:expected_content) { csv_export_file.read } |
|
|
|
let(:expected_content) { csv_export_file.read } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
Timecop.freeze(Time.utc(2022, 6, 5)) |
|
|
|
lettings_log = FactoryBot.create(:lettings_log, needstype: 2, scheme:, location:, owning_organisation: scheme.owning_organisation, created_by: user, rent_type: 2, startdate: Time.zone.local(2021, 10, 2), created_at: Time.zone.local(2022, 2, 8, 16, 52, 15), updated_at: Time.zone.local(2022, 2, 8, 16, 52, 15)) |
|
|
|
lettings_log = FactoryBot.create(:lettings_log, needstype: 2, scheme:, location:, owning_organisation: scheme.owning_organisation, created_by: user, rent_type: 2, startdate: Time.zone.local(2021, 10, 2)) |
|
|
|
|
|
|
|
expected_content.sub!(/\{id\}/, lettings_log["id"].to_s) |
|
|
|
expected_content.sub!(/\{id\}/, lettings_log["id"].to_s) |
|
|
|
expected_content.sub!(/\{scheme_code\}/, "S#{scheme['id']}") |
|
|
|
expected_content.sub!(/\{scheme_code\}/, "S#{scheme['id']}") |
|
|
|
expected_content.sub!(/\{scheme_service_name\}/, scheme["service_name"].to_s) |
|
|
|
expected_content.sub!(/\{scheme_service_name\}/, scheme["service_name"].to_s) |
|
|
|
@ -2707,10 +2850,6 @@ RSpec.describe LettingsLog do |
|
|
|
expected_content.sub!(/\{location_id\}/, location["id"].to_s) |
|
|
|
expected_content.sub!(/\{location_id\}/, location["id"].to_s) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
after do |
|
|
|
|
|
|
|
Timecop.unfreeze |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "with a support user" do |
|
|
|
context "with a support user" do |
|
|
|
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download.csv", "r:UTF-8") } |
|
|
|
let(:csv_export_file) { File.open("spec/fixtures/files/lettings_logs_download.csv", "r:UTF-8") } |
|
|
|
|
|
|
|
|
|
|
|
|