Browse Source

CLDC-1885 Bulk upload type must match given needs type (#1288)

* bulk upload type must match given needs type

* refactor invert logic statement

* tweak validation copy
pull/1301/head
Phil Lee 2 years ago committed by GitHub
parent
commit
f0a1e18325
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/bulk_upload.rb
  2. 15
      app/services/bulk_upload/lettings/row_parser.rb
  3. 3
      config/locales/en.yml
  4. 40
      spec/services/bulk_upload/lettings/row_parser_spec.rb

4
app/models/bulk_upload.rb

@ -42,6 +42,10 @@ class BulkUpload < ApplicationRecord
needstype == 1 needstype == 1
end end
def supported_housing?
needstype == 2
end
private private
def generate_identifier def generate_identifier

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

@ -148,7 +148,8 @@ class BulkUpload::Lettings::RowParser
validate :validate_relevant_collection_window validate :validate_relevant_collection_window
validate :validate_la_with_local_housing_referral 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
validate :leaving_reason_for_renewal validate :validate_leaving_reason_for_renewal
validate :validate_lettings_type_matches_bulk_upload
def valid? def valid?
errors.clear errors.clear
@ -171,6 +172,16 @@ class BulkUpload::Lettings::RowParser
private private
def validate_lettings_type_matches_bulk_upload
if [1, 3, 5, 7, 9, 11].include?(field_1) && !bulk_upload.general_needs?
errors.add(:field_1, I18n.t("validations.setup.lettype.supported_housing_mismatch"))
end
if [2, 4, 6, 8, 10, 12].include?(field_1) && !bulk_upload.supported_housing?
errors.add(:field_1, I18n.t("validations.setup.lettype.general_needs_mismatch"))
end
end
def validate_cannot_be_la_referral_if_general_needs def validate_cannot_be_la_referral_if_general_needs
if field_78 == 4 && bulk_upload.general_needs? if field_78 == 4 && bulk_upload.general_needs?
errors.add :field_78, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la") errors.add :field_78, I18n.t("validations.household.referral.la_general_needs.prp_referred_by_la")
@ -183,7 +194,7 @@ private
end end
end end
def leaving_reason_for_renewal def validate_leaving_reason_for_renewal
if field_134 == 1 && ![40, 42].include?(field_52) if field_134 == 1 && ![40, 42].include?(field_52)
errors.add(:field_52, I18n.t("validations.household.reason.renewal_reason_needed")) errors.add(:field_52, I18n.t("validations.household.reason.renewal_reason_needed"))
end end

3
config/locales/en.yml

@ -170,6 +170,9 @@ en:
invalid: "Please select owning organisation or managing organisation that you belong to" invalid: "Please select owning organisation or managing organisation that you belong to"
created_by: created_by:
invalid: "Please select owning organisation or managing organisation that you belong to" invalid: "Please select owning organisation or managing organisation that you belong to"
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
property: property:
mrcdate: mrcdate:

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

@ -202,6 +202,46 @@ RSpec.describe BulkUpload::Lettings::RowParser do
expect(parser.errors[:field_1]).to be_blank expect(parser.errors[:field_1]).to be_blank
end end
end end
context "when bulk upload is for general needs" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: "1") }
context "when general needs option selected" do
let(:attributes) { { bulk_upload:, field_1: "1" } }
it "is permitted" do
expect(parser.errors[:field_1]).to be_blank
end
end
context "when supported housing option selected" do
let(:attributes) { { bulk_upload:, field_1: "2" } }
it "is not permitted" do
expect(parser.errors[:field_1]).to include("Lettings type must be a general needs type because you selected general needs when uploading the file")
end
end
end
context "when bulk upload is for supported housing" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: "2") }
context "when general needs option selected" do
let(:attributes) { { bulk_upload:, field_1: "1" } }
it "is not permitted" do
expect(parser.errors[:field_1]).to include("Lettings type must be a supported housing type because you selected supported housing when uploading the file")
end
end
context "when supported housing option selected" do
let(:attributes) { { bulk_upload:, field_1: "2" } }
it "is permitted" do
expect(parser.errors[:field_1]).to be_blank
end
end
end
end end
describe "#field_4" do describe "#field_4" do

Loading…
Cancel
Save