diff --git a/spec/models/bulk_upload_spec.rb b/spec/models/bulk_upload_spec.rb index d4626bc4d..da95546dd 100644 --- a/spec/models/bulk_upload_spec.rb +++ b/spec/models/bulk_upload_spec.rb @@ -22,19 +22,67 @@ RSpec.describe BulkUpload, type: :model do end describe "value check clearing" do - context "with a lettings log bulk upload" do - let(:log) { build(:lettings_log, startdate: current_collection_start_date, bulk_upload:) } + context "when 2025", metadata: { year: 25 } do + let(:startdate) { collection_start_date_for_year(2025) } + let(:saledate) { collection_start_date_for_year(2025) } - it "has the correct number of value checks to be set as confirmed" do - expect(bulk_upload.fields_to_confirm(log)).to match_array %w[rent_value_check void_date_value_check major_repairs_date_value_check pregnancy_value_check retirement_value_check referral_value_check net_income_value_check scharge_value_check pscharge_value_check supcharg_value_check multiple_partners_value_check partner_under_16_value_check reasonother_value_check] + context "with a lettings log bulk upload" do + let(:log) { build(:lettings_log, startdate:, bulk_upload:) } + + it "has the correct number of value checks to be set as confirmed" do + expect(bulk_upload.fields_to_confirm(log)).to match_array %w[rent_value_check void_date_value_check major_repairs_date_value_check pregnancy_value_check retirement_value_check referral_value_check net_income_value_check scharge_value_check pscharge_value_check supcharg_value_check multiple_partners_value_check partner_under_16_value_check reasonother_value_check] + end + end + + context "with a sales log bulk upload" do + let(:log) { build(:sales_log, saledate:, bulk_upload:) } + + it "has the correct number of value checks to be set as confirmed" do + expect(bulk_upload.fields_to_confirm(log)).to match_array %w[value_value_check monthly_charges_value_check percentage_discount_value_check income1_value_check income2_value_check combined_income_value_check retirement_value_check old_persons_shared_ownership_value_check buyer_livein_value_check wheel_value_check mortgage_value_check savings_value_check deposit_value_check staircase_bought_value_check stairowned_value_check hodate_check shared_ownership_deposit_value_check extrabor_value_check grant_value_check discounted_sale_value_check deposit_and_mortgage_value_check multiple_partners_value_check partner_under_16_value_check] + end + end + end + + context "when 2026", metadata: { year: 26 } do + let(:startdate) { collection_start_date_for_year(2026) } + let(:saledate) { collection_start_date_for_year(2026) } + + context "with a lettings log bulk upload" do + let(:log) { build(:lettings_log, startdate:, bulk_upload:) } + + it "has the correct number of value checks to be set as confirmed" do + expect(bulk_upload.fields_to_confirm(log)).to match_array %w[rent_value_check void_date_value_check major_repairs_date_value_check pregnancy_value_check retirement_value_check net_income_value_check scharge_value_check pscharge_value_check supcharg_value_check reasonother_value_check tenancyother_value_check working_situation_illness_check] + end + end + + context "with a sales log bulk upload" do + let(:log) { build(:sales_log, saledate:, bulk_upload:) } + + it "has the correct number of value checks to be set as confirmed" do + expect(bulk_upload.fields_to_confirm(log)).to match_array %w[value_value_check monthly_charges_value_check percentage_discount_value_check income1_value_check income2_value_check combined_income_value_check retirement_value_check old_persons_shared_ownership_value_check buyer_livein_value_check wheel_value_check mortgage_value_check savings_value_check deposit_value_check staircase_bought_value_check stairowned_value_check hodate_check shared_ownership_deposit_value_check extrabor_value_check grant_value_check discounted_sale_value_check deposit_and_mortgage_value_check multiple_partners_value_check partner_under_16_value_check] + end end end - context "with a sales log bulk upload" do - let(:log) { build(:sales_log, saledate: current_collection_start_date, bulk_upload:) } + # included to ensure we're testing the next collection we're working on before go live + context "when next collection year" do + let(:startdate) { next_collection_start_date } + let(:saledate) { next_collection_start_date } + + context "with a lettings log bulk upload" do + let(:log) { build(:lettings_log, startdate:, bulk_upload:) } - it "has the correct number of value checks to be set as confirmed" do - expect(bulk_upload.fields_to_confirm(log)).to match_array %w[value_value_check monthly_charges_value_check percentage_discount_value_check income1_value_check income2_value_check combined_income_value_check retirement_value_check old_persons_shared_ownership_value_check buyer_livein_value_check wheel_value_check mortgage_value_check savings_value_check deposit_value_check staircase_bought_value_check stairowned_value_check hodate_check shared_ownership_deposit_value_check extrabor_value_check grant_value_check discounted_sale_value_check deposit_and_mortgage_value_check multiple_partners_value_check partner_under_16_value_check] + it "has the correct number of value checks to be set as confirmed" do + expect(bulk_upload.fields_to_confirm(log)).to match_array %w[rent_value_check void_date_value_check major_repairs_date_value_check pregnancy_value_check retirement_value_check net_income_value_check scharge_value_check pscharge_value_check supcharg_value_check reasonother_value_check tenancyother_value_check working_situation_illness_check] + end + end + + context "with a sales log bulk upload" do + let(:log) { build(:sales_log, saledate:, bulk_upload:) } + + it "has the correct number of value checks to be set as confirmed" do + expect(bulk_upload.fields_to_confirm(log)).to match_array %w[value_value_check monthly_charges_value_check percentage_discount_value_check income1_value_check income2_value_check combined_income_value_check retirement_value_check old_persons_shared_ownership_value_check buyer_livein_value_check wheel_value_check mortgage_value_check savings_value_check deposit_value_check staircase_bought_value_check stairowned_value_check hodate_check shared_ownership_deposit_value_check extrabor_value_check grant_value_check discounted_sale_value_check deposit_and_mortgage_value_check multiple_partners_value_check partner_under_16_value_check] + end end end end diff --git a/spec/models/form/lettings/questions/hhmemb_spec.rb b/spec/models/form/lettings/questions/hhmemb_spec.rb index cc9243923..680dea66d 100644 --- a/spec/models/form/lettings/questions/hhmemb_spec.rb +++ b/spec/models/form/lettings/questions/hhmemb_spec.rb @@ -8,8 +8,9 @@ RSpec.describe Form::Lettings::Questions::Hhmemb, type: :model do let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } let(:subsection) { instance_double(Form::Subsection) } - let(:start_year_2026_or_later?) { false } - let(:form) { instance_double(Form, start_date: current_collection_start_date, start_year_2026_or_later?: start_year_2026_or_later?) } + let(:start_year_2026_or_later?) { true } + let(:startdate) { current_collection_start_date } + let(:form) { instance_double(Form, start_date:, start_year_2026_or_later?: start_year_2026_or_later?) } before do allow(page).to receive(:subsection).and_return(subsection) @@ -37,6 +38,9 @@ RSpec.describe Form::Lettings::Questions::Hhmemb, type: :model do end context "when in 2025", { year: 25 } do + let(:start_year_2026_or_later?) { false } + let(:startdate) { collection_start_date_for_year(2025) } + it "does not have check answers card title" do expect(question.check_answers_card_title).to be_nil end @@ -48,6 +52,7 @@ RSpec.describe Form::Lettings::Questions::Hhmemb, type: :model do context "when in 2026", { year: 26 } do let(:start_year_2026_or_later?) { true } + let(:startdate) { collection_start_date_for_year(2026) } it "has correct check answers card title" do expect(question.check_answers_card_title).to eq("Household") diff --git a/spec/models/lettings_log_derived_fields_spec.rb b/spec/models/lettings_log_derived_fields_spec.rb index c33460147..26bfec121 100644 --- a/spec/models/lettings_log_derived_fields_spec.rb +++ b/spec/models/lettings_log_derived_fields_spec.rb @@ -1068,26 +1068,52 @@ RSpec.describe LettingsLog, type: :model do describe "variables dependent on whether a letting is a renewal" do let(:organisation) { create(:organisation) } let(:user) { create(:user, organisation:) } - let(:startdate) { Time.zone.today } let(:persisted_renewal_lettings_log) { create(:lettings_log, :setup_completed, startdate:, renewal: 1, assigned_to: user) } - it "derives waityear offered referral first_time_property_let_as_social_housing rsnvac when renewal" do - log.renewal = 1 - expect { log.set_derived_fields! } - .to change(log, :waityear).to(2) - .and change(log, :offered).to(0) - .and change(log, :referral).to(1) - .and change(log, :first_time_property_let_as_social_housing).to(0) - .and change(log, :rsnvac).to(14) + context "when 2025", metadata: { year: 25 } do + let(:startdate) { collection_start_date_for_year(2025) } + + it "derives waityear offered referral first_time_property_let_as_social_housing rsnvac when renewal" do + log.renewal = 1 + expect { log.set_derived_fields! } + .to change(log, :waityear).to(2) + .and change(log, :offered).to(0) + .and change(log, :referral).to(1) + .and change(log, :first_time_property_let_as_social_housing).to(0) + .and change(log, :rsnvac).to(14) + end + + it "clears waityear offered referral first_time_property_let_as_social_housing rsnvac when not a renewal" do + expect { persisted_renewal_lettings_log.update!(renewal: 0) } + .to change(persisted_renewal_lettings_log, :waityear).from(2).to(nil) + .and change(persisted_renewal_lettings_log, :offered).from(0).to(nil) + .and change(persisted_renewal_lettings_log, :referral).from(1).to(nil) + .and change(persisted_renewal_lettings_log, :first_time_property_let_as_social_housing).from(0).to(nil) + .and change(persisted_renewal_lettings_log, :rsnvac).from(14).to(nil) + end end - it "clears waityear offered referral first_time_property_let_as_social_housing rsnvac when not a renewal" do - expect { persisted_renewal_lettings_log.update!(renewal: 0) } - .to change(persisted_renewal_lettings_log, :waityear).from(2).to(nil) - .and change(persisted_renewal_lettings_log, :offered).from(0).to(nil) - .and change(persisted_renewal_lettings_log, :referral).from(1).to(nil) - .and change(persisted_renewal_lettings_log, :first_time_property_let_as_social_housing).from(0).to(nil) - .and change(persisted_renewal_lettings_log, :rsnvac).from(14).to(nil) + context "when 2026", metadata: { year: 26 } do + let(:startdate) { collection_start_date_for_year(2026) } + + it "derives waityear offered referral first_time_property_let_as_social_housing rsnvac when renewal" do + log.renewal = 1 + expect { log.set_derived_fields! } + .to change(log, :waityear).to(2) + .and change(log, :offered).to(0) + .and change(log, :referral_register).to(1) + .and change(log, :first_time_property_let_as_social_housing).to(0) + .and change(log, :rsnvac).to(14) + end + + it "clears waityear offered referral first_time_property_let_as_social_housing rsnvac when not a renewal" do + expect { persisted_renewal_lettings_log.update!(renewal: 0) } + .to change(persisted_renewal_lettings_log, :waityear).from(2).to(nil) + .and change(persisted_renewal_lettings_log, :offered).from(0).to(nil) + .and change(persisted_renewal_lettings_log, :referral_register).from(1).to(nil) + .and change(persisted_renewal_lettings_log, :first_time_property_let_as_social_housing).from(0).to(nil) + .and change(persisted_renewal_lettings_log, :rsnvac).from(14).to(nil) + end end describe "deriving voiddate from startdate" do diff --git a/spec/models/organisation_name_change_spec.rb b/spec/models/organisation_name_change_spec.rb index db32874bd..5d45dd818 100644 --- a/spec/models/organisation_name_change_spec.rb +++ b/spec/models/organisation_name_change_spec.rb @@ -30,13 +30,13 @@ RSpec.describe OrganisationNameChange, type: :model do it "is invalid if name is the same as the current name on the change date" do create(:organisation_name_change, organisation:, name: "New Name", startdate: 1.day.ago) - name_change = build(:organisation_name_change, organisation:, name: "New Name", startdate: Time.zone.now) + name_change = build(:organisation_name_change, organisation:, name: "New Name", startdate: Time.zone.today) expect(name_change).not_to be_valid expect(name_change.errors[:name]).to include(I18n.t("validations.organisation.name_changes.name.must_be_different")) end it "is invalid if startdate is after the organisation's merge date" do - organisation.update!(merge_date: Time.zone.now) + organisation.update!(merge_date: Time.zone.today) name_change = build(:organisation_name_change, organisation:, immediate_change: false, startdate: Time.zone.tomorrow) expect(name_change).not_to be_valid expect(name_change.errors[:startdate]).to include(I18n.t("validations.organisation.name_changes.startdate.must_be_before_merge_date", merge_date: organisation.merge_date.to_formatted_s(:govuk_date))) @@ -54,12 +54,12 @@ RSpec.describe OrganisationNameChange, type: :model do it "returns changes before a specific date" do name_change = create(:organisation_name_change, organisation:, startdate: 1.day.ago) - expect(described_class.before_date(Time.zone.now)).to include(name_change) + expect(described_class.before_date(Time.zone.today)).to include(name_change) end it "returns changes after a specific date" do name_change = create(:organisation_name_change, organisation:, startdate: 2.days.from_now) - expect(described_class.after_date(Time.zone.now)).to include(name_change) + expect(described_class.after_date(Time.zone.today)).to include(name_change) end end @@ -84,7 +84,7 @@ RSpec.describe OrganisationNameChange, type: :model do describe "#includes_date?" do it "returns true if the date is within the change period" do name_change = create(:organisation_name_change, organisation:, startdate: 1.day.ago) - expect(name_change.includes_date?(Time.zone.now)).to be true + expect(name_change.includes_date?(Time.zone.today)).to be true end it "returns false if the date is outside the change period" do diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 01a76ab39..046c00b92 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -688,8 +688,9 @@ RSpec.describe SalesLog, type: :model do create( :sales_log, :completed, + saledate:, jointpur: 1, - hholdcount: 4, + hholdcount:, details_known_3: 1, details_known_4: 1, details_known_5: 1, @@ -711,30 +712,66 @@ RSpec.describe SalesLog, type: :model do ) end - it "correctly derives and saves hhmemb" do - record_from_db = described_class.find(sales_log.id) - expect(record_from_db["hhmemb"]).to eq(6) - end + context "when 2025", metadata: { year: 2025 } do + let(:saledate) { collection_start_date_for_year(2025) } + let(:hholdcount) { 4 } - it "correctly derives and saves hhmemb if it's a joint purchase" do - sales_log.update!(jointpur: 2, jointmore: 2) - record_from_db = described_class.find(sales_log.id) - expect(record_from_db["hhmemb"]).to eq(5) - end + it "correctly derives and saves hhmemb" do + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["hhmemb"]).to eq(6) + end - it "correctly derives and saves totchild" do - record_from_db = described_class.find(sales_log.id) - expect(record_from_db["totchild"]).to eq(2) - end + it "correctly derives and saves hhmemb if it's a joint purchase" do + sales_log.update!(jointpur: 2, jointmore: 2) + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["hhmemb"]).to eq(5) + end - it "correctly derives and saves totadult" do - record_from_db = described_class.find(sales_log.id) - expect(record_from_db["totadult"]).to eq(4) + it "correctly derives and saves totchild" do + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["totchild"]).to eq(2) + end + + it "correctly derives and saves totadult" do + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["totadult"]).to eq(4) + end + + it "correctly derives and saves hhtype" do + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["hhtype"]).to eq(9) + end end - it "correctly derives and saves hhtype" do - record_from_db = described_class.find(sales_log.id) - expect(record_from_db["hhtype"]).to eq(9) + context "when 2026", metadata: { year: 2026 } do + let(:saledate) { collection_start_date_for_year(2026) } + let(:hholdcount) { 6 } + + it "correctly derives and saves hhmemb" do + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["hhmemb"]).to eq(6) + end + + it "correctly derives and saves hhmemb if it's a joint purchase" do + sales_log.update!(jointpur: 2, jointmore: 2) + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["hhmemb"]).to eq(6) + end + + it "correctly derives and saves totchild" do + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["totchild"]).to eq(2) + end + + it "correctly derives and saves totadult" do + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["totadult"]).to eq(4) + end + + it "correctly derives and saves hhtype" do + record_from_db = described_class.find(sales_log.id) + expect(record_from_db["hhtype"]).to eq(9) + end end end @@ -806,10 +843,10 @@ RSpec.describe SalesLog, type: :model do end describe "expected_shared_ownership_deposit_value" do - let!(:completed_sales_log) { create(:sales_log, :completed, ownershipsch: 1, type: 2, value: 1000, equity: 50, staircase: 1) } + let!(:completed_sales_log) { create(:sales_log, :completed, ownershipsch: 1, type: 2, value: 15_000, equity: 50, staircase: 1) } it "is set to completed for a completed sales log" do - expect(completed_sales_log.expected_shared_ownership_deposit_value).to eq(500) + expect(completed_sales_log.expected_shared_ownership_deposit_value).to eq(7500) end end diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 3cd05bb88..583892b11 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe Validations::PropertyValidations do + include CollectionTimeHelper + subject(:property_validator) { property_validator_class.new } let(:property_validator_class) { Class.new { include Validations::PropertyValidations } } @@ -316,42 +318,65 @@ RSpec.describe Validations::PropertyValidations do end end - context "and the local authority is active for supported housing log" do - let(:location) { create(:location, location_code: la_ecode_active) } - let(:log) { build(:lettings_log, :completed, needstype: 2, location:) } + context "when 2025", metadata: { year: 25 } do + let(:startdate) { collection_start_date_for_year(2025) } - it "does not add an error" do - property_validator.validate_la_is_active(log) - expect(log.errors["scheme_id"]).to be_empty - expect(log.errors["location_id"]).to be_empty - expect(log.errors["startdate"]).to be_empty - expect(log.errors["la"]).to be_empty - expect(log.errors["postcode_full"]).to be_empty - expect(log.errors["uprn"]).to be_empty - expect(log.errors["uprn_selection"]).to be_empty + context "and the local authority is active for supported housing log" do + let(:location) { create(:location, location_code: la_ecode_active) } + let(:log) { build(:lettings_log, :completed, startdate:, needstype: 2, location:) } + + it "does not add an error" do + property_validator.validate_la_is_active(log) + expect(log.errors["scheme_id"]).to be_empty + expect(log.errors["location_id"]).to be_empty + expect(log.errors["startdate"]).to be_empty + expect(log.errors["la"]).to be_empty + expect(log.errors["postcode_full"]).to be_empty + expect(log.errors["uprn"]).to be_empty + expect(log.errors["uprn_selection"]).to be_empty + end end - end - context "and the local authority is inactive for supported housing log" do - let(:location) { create(:location, location_code: la_ecode_inactive) } - let(:log) { build(:lettings_log, :completed, needstype: 2, location:) } + context "and the local authority is inactive for supported housing log" do + let(:location) { create(:location, location_code: la_ecode_inactive) } + let(:log) { build(:lettings_log, :completed, startdate:, needstype: 2, location:) } + + context "and the inactive local authority is not linked to an active one" do + it "adds an error" do + property_validator.validate_la_is_active(log) + expect(log.errors["scheme_id"]).to include(I18n.t("validations.lettings.property.scheme_id.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["location_id"]).to include(I18n.t("validations.lettings.property.location_id.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["la"]).to include(I18n.t("validations.lettings.property.la.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["postcode_full"]).to include(I18n.t("validations.lettings.property.postcode_full.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.la_not_valid_for_date", la: local_authority_inactive.name)) + end + end - context "and the inactive local authority is not linked to an active one" do - it "adds an error" do - property_validator.validate_la_is_active(log) - expect(log.errors["scheme_id"]).to include(I18n.t("validations.lettings.property.scheme_id.la_not_valid_for_date", la: local_authority_inactive.name)) - expect(log.errors["location_id"]).to include(I18n.t("validations.lettings.property.location_id.la_not_valid_for_date", la: local_authority_inactive.name)) - expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.la_not_valid_for_date", la: local_authority_inactive.name)) - expect(log.errors["la"]).to include(I18n.t("validations.lettings.property.la.la_not_valid_for_date", la: local_authority_inactive.name)) - expect(log.errors["postcode_full"]).to include(I18n.t("validations.lettings.property.postcode_full.la_not_valid_for_date", la: local_authority_inactive.name)) - expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.la_not_valid_for_date", la: local_authority_inactive.name)) - expect(log.errors["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.la_not_valid_for_date", la: local_authority_inactive.name)) + context "and the inactive local authority is linked to an active one" do + it "does not add an error" do + LocalAuthorityLink.create!(local_authority: local_authority_inactive, linked_local_authority: local_authority_active) + property_validator.validate_la_is_active(log) + expect(log.errors["scheme_id"]).to be_empty + expect(log.errors["location_id"]).to be_empty + expect(log.errors["startdate"]).to be_empty + expect(log.errors["la"]).to be_empty + expect(log.errors["postcode_full"]).to be_empty + expect(log.errors["uprn"]).to be_empty + expect(log.errors["uprn_selection"]).to be_empty + end end end + end + + context "when 2026", metadata: { year: 26 } do + let(:startdate) { collection_start_date_for_year(2026) } + + context "and the local authority is active for supported housing log" do + let(:log) { build(:lettings_log, :completed, startdate:, la: la_ecode_active, needstype: 2) } - context "and the inactive local authority is linked to an active one" do it "does not add an error" do - LocalAuthorityLink.create!(local_authority: local_authority_inactive, linked_local_authority: local_authority_active) property_validator.validate_la_is_active(log) expect(log.errors["scheme_id"]).to be_empty expect(log.errors["location_id"]).to be_empty @@ -362,6 +387,38 @@ RSpec.describe Validations::PropertyValidations do expect(log.errors["uprn_selection"]).to be_empty end end + + context "and the local authority is inactive for supported housing log" do + let(:log) { build(:lettings_log, :completed, startdate:, la: la_ecode_inactive, needstype: 2) } + + context "and the inactive local authority is not linked to an active one" do + it "adds an error" do + property_validator.validate_la_is_active(log) + expect(log.errors["scheme_id"]).to include(I18n.t("validations.lettings.property.scheme_id.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["location_id"]).to include(I18n.t("validations.lettings.property.location_id.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["la"]).to include(I18n.t("validations.lettings.property.la.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["postcode_full"]).to include(I18n.t("validations.lettings.property.postcode_full.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.la_not_valid_for_date", la: local_authority_inactive.name)) + end + end + + context "and the inactive local authority is linked to an active one" do + # the link code was only ever used if the LA was drawn from the location + it "adds an error" do + LocalAuthorityLink.create!(local_authority: local_authority_inactive, linked_local_authority: local_authority_active) + property_validator.validate_la_is_active(log) + expect(log.errors["scheme_id"]).to include(I18n.t("validations.lettings.property.scheme_id.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["location_id"]).to include(I18n.t("validations.lettings.property.location_id.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["la"]).to include(I18n.t("validations.lettings.property.la.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["postcode_full"]).to include(I18n.t("validations.lettings.property.postcode_full.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.la_not_valid_for_date", la: local_authority_inactive.name)) + end + end + end end end