From 748b84673926e743d848b841c8ac9c2d23191cf3 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 24 Aug 2023 14:53:17 +0100 Subject: [PATCH] Add incomplete location validation --- app/models/validations/setup_validations.rb | 5 +++++ config/locales/en.yml | 2 ++ .../validations/setup_validations_spec.rb | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/app/models/validations/setup_validations.rb b/app/models/validations/setup_validations.rb index d3f72a365..e826c6302 100644 --- a/app/models/validations/setup_validations.rb +++ b/app/models/validations/setup_validations.rb @@ -26,6 +26,11 @@ module Validations::SetupValidations def validate_location(record) location_during_startdate_validation(record) + + if record.location&.status == :incomplete + record.errors.add :location_id, :incomplete, message: I18n.t("validations.setup.location.incomplete") + record.errors.add :scheme_id, :incomplete, message: I18n.t("validations.setup.location.incomplete") + end end def validate_scheme_has_confirmed_locations_validation(record) diff --git a/config/locales/en.yml b/config/locales/en.yml index 0cf265b08..3ee86b7f0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -305,6 +305,8 @@ en: lettype: general_needs_mismatch: Lettings type must be a general needs type because you selected general needs when uploading the file supported_housing_mismatch: Lettings type must be a supported housing type because you selected supported housing when uploading the file + location: + incomplete: "This location is incomplete" property: uprn: diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index 3def42da4..249c16487 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -641,6 +641,26 @@ RSpec.describe Validations::SetupValidations do .to include(match I18n.t("validations.setup.startdate.location.activating_soon.location_id", postcode: location.postcode, date: "15 September 2022")) end end + + context "with an incomplete location" do + let(:scheme) { create(:scheme) } + let(:location) { create(:location, :incomplete, scheme:) } + + it "produces error when location is incomplete" do + record.location = location + setup_validator.validate_location(record) + expect(record.errors["location_id"]) + .to include("This location is incomplete") + end + + it "produces no error when location is completes" do + location.update!(units: 1) + location.reload + record.location = location + setup_validator.validate_location(record) + expect(record.errors["location_id"]).to be_empty + end + end end describe "#validate_organisation" do