Browse Source

tweak bulk upload validation (#1302)

- LA referral not permitted if general needs and now also if owning
  org is an LA
pull/1319/head
Phil Lee 2 years ago committed by GitHub
parent
commit
02d8247f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/services/bulk_upload/lettings/row_parser.rb
  2. 4
      spec/factories/organisation.rb
  3. 14
      spec/services/bulk_upload/lettings/row_parser_spec.rb

6
app/services/bulk_upload/lettings/row_parser.rb

@ -147,7 +147,7 @@ class BulkUpload::Lettings::RowParser
validate :validate_nulls
validate :validate_relevant_collection_window
validate :validate_la_with_local_housing_referral
validate :validate_cannot_be_la_referral_if_general_needs
validate :validate_cannot_be_la_referral_if_general_needs_and_la
validate :validate_leaving_reason_for_renewal
validate :validate_lettings_type_matches_bulk_upload
validate :validate_only_one_housing_needs_type
@ -219,8 +219,8 @@ private
end
end
def validate_cannot_be_la_referral_if_general_needs
if field_78 == 4 && bulk_upload.general_needs?
def validate_cannot_be_la_referral_if_general_needs_and_la
if field_78 == 4 && bulk_upload.general_needs? && owning_organisation && owning_organisation.la?
errors.add :field_78, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la")
end
end

4
spec/factories/organisation.rb

@ -13,6 +13,10 @@ FactoryBot.define do
trait :with_old_visible_id do
old_visible_id { rand(9_999_999).to_s }
end
trait :prp do
provider_type { "PRP" }
end
end
factory :organisation_rent_period do

14
spec/services/bulk_upload/lettings/row_parser_spec.rb

@ -396,14 +396,24 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
end
context "when 4 ie referred by LA and is general needs" do
let(:attributes) { { bulk_upload:, field_78: "4" } }
context "when 4 ie referred by LA and is general needs and owning org is LA" do
let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id.to_s } }
it "is not permitted" do
expect(parser.errors[:field_78]).to be_present
end
end
context "when 4 ie referred by LA and is general needs and owning org is PRP" do
let(:owning_org) { create(:organisation, :prp, :with_old_visible_id) }
let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id.to_s } }
it "is permitted" do
expect(parser.errors[:field_78]).to be_blank
end
end
context "when 4 ie referred by LA and is not general needs" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) }
let(:attributes) { { bulk_upload:, field_78: "4" } }

Loading…
Cancel
Save