Browse Source

bulk upload validate leaving reason if renewal

pull/1278/head
Phil Lee 3 years ago
parent
commit
9fb1201077
  1. 9
      app/services/bulk_upload/lettings/row_parser.rb
  2. 29
      spec/services/bulk_upload/lettings/row_parser_spec.rb

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

@ -148,6 +148,7 @@ class BulkUpload::Lettings::RowParser
validate :validate_relevant_collection_window
validate :validate_la_with_local_housing_referral
validate :validate_cannot_be_la_referral_if_general_needs
validate :leaving_reason_for_renewal
def valid?
errors.clear
@ -182,6 +183,14 @@ private
end
end
def leaving_reason_for_renewal
if field_134 == 1 && ![40, 42].include?(field_52)
message = 'The reason for leaving must be "End of assured shorthold tenancy - no fault" or "End of fixed term tenancy - no fault" if the letting is a renewal'
errors.add(:field_52, message)
end
end
def validate_relevant_collection_window
return unless start_date && bulk_upload.form

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

@ -250,6 +250,35 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
end
describe "#field_52" do # leaving reason
context "when field_134 is 1 meaning it is a renewal" do
context "when field_52 is 40" do
let(:attributes) { { bulk_upload:, field_52: "40", field_134: "1" } }
it "is permitted" do
expect(parser.errors[:field_52]).to be_blank
end
end
context "when field_52 is 42" do
let(:attributes) { { bulk_upload:, field_52: "42", field_134: "1" } }
it "is permitted" do
expect(parser.errors[:field_52]).to be_blank
end
end
context "when field_52 is not 40 or 42" do
let(:attributes) { { bulk_upload:, field_52: "1", field_134: "1" } }
it "is not permitted" do
parser.field_52 = "1"
expect(parser.errors[:field_52]).to be_present
end
end
end
end
describe "#field_78" do # referral
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 } }

Loading…
Cancel
Save