From 1b558e23efaba6f29b1d155b8a649578c7773c1b Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Wed, 8 Oct 2025 16:27:14 +0100 Subject: [PATCH] CLDC-4090: Add verifying tests --- .../validations/property_validations_spec.rb | 96 +++++++++++++++++++ .../sales/property_validations_spec.rb | 61 ++++++++++++ 2 files changed, 157 insertions(+) diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index f4e5fe6f2..97f5c287c 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -280,4 +280,100 @@ RSpec.describe Validations::PropertyValidations do end end end + + describe "#validate_la_is_active" do + let(:la_ecode_active) { "E09000033" } + let(:la_ecode_inactive) { "E07000156" } + let(:local_authority_active) { LocalAuthority.find_by(code: la_ecode_active) } + let(:local_authority_inactive) { LocalAuthority.find_by(code: la_ecode_inactive) } + + context "with a log on or after 2025" do + before do + allow(log.form).to receive(:start_year_2025_or_later?).and_return true + end + + context "and the local authority is active for general needs log" do + let(:log) { build(:lettings_log, :completed, la: la_ecode_active, needstype: 1) } + + it "does not add an error" do + property_validator.validate_la_is_active(log) + 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_confirmation"]).to be_empty + expect(log.errors["uprn_selection"]).to be_empty + expect(log.errors["startdate"]).to be_empty + end + end + + context "and the local authority is inactive for general needs log" do + let(:log) { build(:lettings_log, :completed, la: la_ecode_inactive, needstype: 1) } + + it "adds an error" do + property_validator.validate_la_is_active(log) + 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_confirmation"]).to include(I18n.t("validations.lettings.property.uprn_confirmation.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)) + 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["scheme_id"]).to be_empty + expect(log.errors["location_id"]).to be_empty + 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:) } + + 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_confirmation"]).to be_empty + expect(log.errors["uprn_selection"]).to be_empty + 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:) } + + 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 be_empty + expect(log.errors["postcode_full"]).to be_empty + expect(log.errors["uprn"]).to be_empty + expect(log.errors["uprn_confirmation"]).to be_empty + expect(log.errors["uprn_selection"]).to be_empty + end + end + end + + context "with a log before 2025" do + before do + allow(log.form).to receive(:start_year_2025_or_later?).and_return false + end + + context "and the local authority is inactive" do + let(:log) { build(:lettings_log, :completed, la: la_ecode_inactive) } + + it "does not add an error" do + property_validator.validate_la_is_active(log) + 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_confirmation"]).to be_empty + expect(log.errors["uprn_selection"]).to be_empty + end + end + end + end end diff --git a/spec/models/validations/sales/property_validations_spec.rb b/spec/models/validations/sales/property_validations_spec.rb index ce6585956..6b141b436 100644 --- a/spec/models/validations/sales/property_validations_spec.rb +++ b/spec/models/validations/sales/property_validations_spec.rb @@ -139,4 +139,65 @@ RSpec.describe Validations::Sales::PropertyValidations do end end end + + describe "#validate_la_is_active" do + let(:la_ecode_active) { "E09000033" } + let(:la_ecode_inactive) { "E07000156" } + let(:local_authority_active) { LocalAuthority.find_by(code: la_ecode_active) } + let(:local_authority_inactive) { LocalAuthority.find_by(code: la_ecode_inactive) } + + context "with a log on or after 2025" do + before do + allow(log.form).to receive(:start_year_2025_or_later?).and_return true + end + + context "and the local authority is active" do + let(:log) { build(:sales_log, :completed, la: la_ecode_active) } + + it "adds an error" do + property_validator.validate_la_is_active(log) + 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_confirmation"]).to be_empty + expect(log.errors["uprn_selection"]).to be_empty + expect(log.errors["saledate"]).to be_empty + end + end + + context "and the local authority is inactive" do + let(:log) { build(:sales_log, :completed, la: la_ecode_inactive) } + + it "does not add an error" do + property_validator.validate_la_is_active(log) + expect(log.errors["la"]).to include(I18n.t("validations.sales.property_information.la.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["postcode_full"]).to include(I18n.t("validations.sales.property_information.postcode_full.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn"]).to include(I18n.t("validations.sales.property_information.uprn.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn_confirmation"]).to include(I18n.t("validations.sales.property_information.uprn_confirmation.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn_selection"]).to include(I18n.t("validations.sales.property_information.uprn_selection.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["saledate"]).to include(I18n.t("validations.sales.property_information.saledate.la_not_valid_for_date", la: local_authority_inactive.name)) + end + end + end + + context "with a log before 2025" do + before do + allow(log.form).to receive(:start_year_2025_or_later?).and_return false + end + + context "and the local authority is inactive" do + let(:log) { build(:sales_log, :completed, la: la_ecode_inactive) } + + it "does not add an error" do + property_validator.validate_la_is_active(log) + 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_confirmation"]).to be_empty + expect(log.errors["uprn_selection"]).to be_empty + expect(log.errors["saledate"]).to be_empty + end + end + end + end end