Browse Source

better validation on bulk upload start year (#1319)

pull/1322/head v0.2.40
Phil Lee 2 years ago committed by GitHub
parent
commit
01b957cc10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/services/bulk_upload/lettings/row_parser.rb
  2. 1
      config/locales/en.yml
  3. 18
      spec/services/bulk_upload/lettings/row_parser_spec.rb

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

@ -143,6 +143,7 @@ class BulkUpload::Lettings::RowParser
validates :field_1, presence: { message: I18n.t("validations.not_answered", question: "letting type") },
inclusion: { in: (1..12).to_a, message: I18n.t("validations.invalid_option", question: "letting type") }
validates :field_4, presence: { if: proc { [2, 4, 6, 8, 10, 12].include?(field_1) } }
validates :field_98, format: { with: /\A\d{2}\z/, message: I18n.t("validations.setup.startdate.year_not_two_digits") }
validate :validate_data_types
validate :validate_nulls
@ -500,6 +501,8 @@ private
def startdate
Date.new(field_98 + 2000, field_97, field_96) if field_98.present? && field_97.present? && field_96.present?
rescue Date::Error
Date.new
end
def renttype

1
config/locales/en.yml

@ -156,6 +156,7 @@ en:
before_scheme_end_date: "The tenancy start date must be before the end date for this supported housing scheme"
after_void_date: "Enter a tenancy start date that is after the void date"
after_major_repair_date: "Enter a tenancy start date that is after the major repair date"
year_not_two_digits: Tenancy start year must be 2 digits
location:
deactivated: "The location %{postcode} was deactivated on %{date} and was not available on the day you entered."
reactivating_soon: "The location %{postcode} is not available until %{date}. Select another location or edit the tenancy start date"

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

@ -443,6 +443,24 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
end
context "when field 98 is 4 digits instead of 2" do
let(:attributes) { { bulk_upload:, field_98: "2022" } }
it "returns an error" do
parser.valid?
expect(parser.errors[:field_98]).to include("Tenancy start year must be 2 digits")
end
end
context "when invalid date given" do
let(:attributes) { { bulk_upload:, field_1: "1", field_96: "a", field_97: "12", field_98: "2022" } }
it "does not raise an error" do
expect { parser.valid? }.not_to raise_error
end
end
context "when inside of collection year" do
let(:attributes) { { bulk_upload:, field_96: "1", field_97: "10", field_98: "22" } }

Loading…
Cancel
Save