Browse Source

CLDC-1883 bulk upload validate LA and local housing referral (#1284)

* bulk upload validate LA and local housing referral

* move validation message to locales
pull/1281/head
Phil Lee 2 years ago committed by GitHub
parent
commit
3b2e24bcff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/organisation.rb
  2. 13
      app/services/bulk_upload/lettings/row_parser.rb
  3. 1
      config/locales/en.yml
  4. 14
      spec/services/bulk_upload/lettings/row_parser_spec.rb

2
app/models/organisation.rb

@ -30,6 +30,8 @@ class Organisation < ApplicationRecord
enum provider_type: PROVIDER_TYPE enum provider_type: PROVIDER_TYPE
alias_method :la?, :LA?
validates :name, presence: { message: I18n.t("validations.organisation.name_missing") } validates :name, presence: { message: I18n.t("validations.organisation.name_missing") }
validates :provider_type, presence: { message: I18n.t("validations.organisation.provider_type_missing") } validates :provider_type, presence: { message: I18n.t("validations.organisation.provider_type_missing") }

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

@ -146,6 +146,7 @@ class BulkUpload::Lettings::RowParser
validate :validate_data_types validate :validate_data_types
validate :validate_nulls validate :validate_nulls
validate :validate_relevant_collection_window validate :validate_relevant_collection_window
validate :validate_la_with_local_housing_referral
def valid? def valid?
errors.clear errors.clear
@ -168,6 +169,12 @@ class BulkUpload::Lettings::RowParser
private private
def validate_la_with_local_housing_referral
if field_78 == 3 && owning_organisation && owning_organisation.la?
errors.add(:field_78, I18n.t("validations.household.referral.nominated_by_local_ha_but_la"))
end
end
def validate_relevant_collection_window def validate_relevant_collection_window
return unless start_date && bulk_upload.form return unless start_date && bulk_upload.form
@ -413,8 +420,12 @@ private
end end
end end
def owning_organisation
Organisation.find_by(old_visible_id: field_111)
end
def owning_organisation_id def owning_organisation_id
Organisation.find_by(old_visible_id: field_111)&.id owning_organisation&.id
end end
def managing_organisation_id def managing_organisation_id

1
config/locales/en.yml

@ -356,6 +356,7 @@ en:
other_homeless: "Answer cannot be internal transfer as the tenant was considered homeless by their landlord" other_homeless: "Answer cannot be internal transfer as the tenant was considered homeless by their landlord"
prevten_invalid: "Answer cannot be internal transfer as the household situation immediately before this letting was %{prevten}" prevten_invalid: "Answer cannot be internal transfer as the household situation immediately before this letting was %{prevten}"
reason_permanently_decanted: "Answer must be internal transfer as the tenant was permanently decanted from another property owned by this landlord" reason_permanently_decanted: "Answer must be internal transfer as the tenant was permanently decanted from another property owned by this landlord"
nominated_by_local_ha_but_la: The source of the referral cannot be Nominated by local housing authority as your organisation is a local authority
la_general_needs: la_general_needs:
internal_transfer: "Answer cannot be internal transfer as it’s the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting" internal_transfer: "Answer cannot be internal transfer as it’s the same landlord on the tenancy agreement and the household had either a fixed-term or lifetime local authority general needs tenancy immediately before this letting"
prp: prp:

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

@ -8,8 +8,8 @@ RSpec.describe BulkUpload::Lettings::RowParser do
let(:attributes) { { bulk_upload: } } let(:attributes) { { bulk_upload: } }
let(:bulk_upload) { create(:bulk_upload, :lettings, user:) } let(:bulk_upload) { create(:bulk_upload, :lettings, user:) }
let(:user) { create(:user, organisation: owning_org) } let(:user) { create(:user, organisation: owning_org) }
let(:owning_org) { create(:organisation) } let(:owning_org) { create(:organisation, :with_old_visible_id) }
let(:managing_org) { create(:organisation) } let(:managing_org) { create(:organisation, :with_old_visible_id) }
let(:setup_section_params) do let(:setup_section_params) do
{ {
bulk_upload:, bulk_upload:,
@ -250,6 +250,16 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end end
end end
describe "#field_78" do
context "when 3 ie PRP nominated by LA and owning org is LA" do
let(:attributes) { { bulk_upload:, field_78: "3", field_111: owning_org.old_visible_id } }
it "is not permitted" do
expect(parser.errors[:field_78]).to be_present
end
end
end
describe "fields 96, 97, 98 => startdate" do describe "fields 96, 97, 98 => startdate" do
context "when any one of these fields is blank" do context "when any one of these fields is blank" do
let(:attributes) { { bulk_upload:, field_96: nil, field_97: nil, field_98: nil } } let(:attributes) { { bulk_upload:, field_96: nil, field_97: nil, field_98: nil } }

Loading…
Cancel
Save