Browse Source

CLDC-2413 Allow 4 digit year format for bulk uploads (#2715)

* Allow 4 digit years for start date/sale date

* Update other dates
pull/2718/head^2
kosiakkatrina 2 months ago committed by GitHub
parent
commit
64caf018e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      app/services/bulk_upload/lettings/year2023/csv_parser.rb
  2. 25
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  3. 6
      app/services/bulk_upload/lettings/year2024/csv_parser.rb
  4. 25
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  5. 6
      app/services/bulk_upload/sales/year2023/csv_parser.rb
  6. 13
      app/services/bulk_upload/sales/year2023/row_parser.rb
  7. 6
      app/services/bulk_upload/sales/year2024/csv_parser.rb
  8. 13
      app/services/bulk_upload/sales/year2024/row_parser.rb
  9. 4
      config/locales/en.yml
  10. 34
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  11. 34
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
  12. 19
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb
  13. 20
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

6
app/services/bulk_upload/lettings/year2023/csv_parser.rb

@ -109,9 +109,11 @@ private
def first_record_start_date def first_record_start_date
if with_headers? if with_headers?
Date.new(row_parsers.first.field_9.to_i + 2000, row_parsers.first.field_8.to_i, row_parsers.first.field_7.to_i) year = row_parsers.first.field_9.to_s.strip.length.between?(1, 2) ? row_parsers.first.field_9.to_i + 2000 : row_parsers.first.field_9.to_i
Date.new(year, row_parsers.first.field_8.to_i, row_parsers.first.field_7.to_i)
else else
Date.new(rows.first[97].to_i + 2000, rows.first[96].to_i, rows.first[95].to_i) year = rows.first[97].to_s.strip.length.between?(1, 2) ? rows.first[97].to_i + 2000 : rows.first[97].to_i
Date.new(year, rows.first[96].to_i, rows.first[95].to_i)
end end
end end
end end

25
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -323,8 +323,8 @@ class BulkUpload::Lettings::Year2023::RowParser
category: :setup, category: :setup,
}, },
format: { format: {
with: /\A\d{2}\z/, with: /\A(\d{2}|\d{4})\z/,
message: I18n.t("validations.setup.startdate.year_not_two_digits"), message: I18n.t("validations.setup.startdate.year_not_two_or_four_digits"),
category: :setup, category: :setup,
unless: -> { field_9.blank? }, unless: -> { field_9.blank? },
}, },
@ -618,14 +618,6 @@ private
end end
end end
def start_date
return if field_7.blank? || field_8.blank? || field_9.blank?
Date.parse("20#{field_9.to_s.rjust(2, '0')}-#{field_8}-#{field_7}")
rescue StandardError
nil
end
def validate_no_and_dont_know_disabled_needs_conjunction def validate_no_and_dont_know_disabled_needs_conjunction
if field_87 == 1 && field_88 == 1 if field_87 == 1 && field_88 == 1
errors.add(:field_87, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) errors.add(:field_87, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction"))
@ -736,9 +728,9 @@ private
end end
def validate_relevant_collection_window def validate_relevant_collection_window
return if start_date.blank? || bulk_upload.form.blank? return if startdate.blank? || bulk_upload.form.blank?
unless bulk_upload.form.valid_start_date_for_form?(start_date) unless bulk_upload.form.valid_start_date_for_form?(startdate)
errors.add(:field_7, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) errors.add(:field_7, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup)
errors.add(:field_8, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) errors.add(:field_8, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup)
errors.add(:field_9, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) errors.add(:field_9, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup)
@ -1388,7 +1380,8 @@ private
end end
def startdate def startdate
Date.new(field_9 + 2000, field_8, field_7) if field_9.present? && field_8.present? && field_7.present? year = field_9.to_s.strip.length.between?(1, 2) ? field_9 + 2000 : field_9
Date.new(year, field_8, field_7) if field_9.present? && field_8.present? && field_7.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end
@ -1584,13 +1577,15 @@ private
end end
def mrcdate def mrcdate
Date.new(field_38 + 2000, field_37, field_36) if field_38.present? && field_37.present? && field_36.present? year = field_38.to_s.strip.length.between?(1, 2) ? field_38 + 2000 : field_38
Date.new(year, field_37, field_36) if field_38.present? && field_37.present? && field_36.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end
def voiddate def voiddate
Date.new(field_35 + 2000, field_34, field_33) if field_35.present? && field_34.present? && field_33.present? year = field_35.to_s.strip.length.between?(1, 2) ? field_35 + 2000 : field_35
Date.new(year, field_34, field_33) if field_35.present? && field_34.present? && field_33.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end

6
app/services/bulk_upload/lettings/year2024/csv_parser.rb

@ -112,9 +112,11 @@ private
def first_record_start_date def first_record_start_date
if with_headers? if with_headers?
Date.new(row_parsers.first.field_10.to_i + 2000, row_parsers.first.field_9.to_i, row_parsers.first.field_8.to_i) year = row_parsers.first.field_10.to_s.strip.length.between?(1, 2) ? row_parsers.first.field_10.to_i + 2000 : row_parsers.first.field_10.to_i
Date.new(year, row_parsers.first.field_9.to_i, row_parsers.first.field_8.to_i)
else else
Date.new(rows.first[9].to_i + 2000, rows.first[8].to_i, rows.first[7].to_i) year = rows.first[9].to_s.strip.length.between?(1, 2) ? rows.first[9].to_i + 2000 : rows.first[9].to_i
Date.new(year, rows.first[8].to_i, rows.first[7].to_i)
end end
end end
end end

25
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -324,8 +324,8 @@ class BulkUpload::Lettings::Year2024::RowParser
category: :setup, category: :setup,
}, },
format: { format: {
with: /\A\d{2}\z/, with: /\A(\d{2}|\d{4})\z/,
message: I18n.t("validations.setup.startdate.year_not_two_digits"), message: I18n.t("validations.setup.startdate.year_not_two_or_four_digits"),
category: :setup, category: :setup,
unless: -> { field_10.blank? }, unless: -> { field_10.blank? },
}, },
@ -686,14 +686,6 @@ private
end end
end end
def start_date
return if field_8.blank? || field_9.blank? || field_10.blank?
Date.parse("20#{field_10.to_s.rjust(2, '0')}-#{field_9}-#{field_8}")
rescue StandardError
nil
end
def validate_no_and_dont_know_disabled_needs_conjunction def validate_no_and_dont_know_disabled_needs_conjunction
if field_83 == 1 && field_84 == 1 if field_83 == 1 && field_84 == 1
errors.add(:field_83, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction")) errors.add(:field_83, I18n.t("validations.household.housingneeds.no_and_dont_know_disabled_needs_conjunction"))
@ -790,9 +782,9 @@ private
end end
def validate_relevant_collection_window def validate_relevant_collection_window
return if start_date.blank? || bulk_upload.form.blank? return if startdate.blank? || bulk_upload.form.blank?
unless bulk_upload.form.valid_start_date_for_form?(start_date) unless bulk_upload.form.valid_start_date_for_form?(startdate)
errors.add(:field_8, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) errors.add(:field_8, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup)
errors.add(:field_9, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) errors.add(:field_9, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup)
errors.add(:field_10, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup) errors.add(:field_10, I18n.t("validations.date.outside_collection_window", year_combo: bulk_upload.year_combo, start_year: bulk_upload.year, end_year: bulk_upload.end_year), category: :setup)
@ -1394,7 +1386,8 @@ private
end end
def startdate def startdate
Date.new(field_10 + 2000, field_9, field_8) if field_10.present? && field_9.present? && field_8.present? year = field_10.to_s.strip.length.between?(1, 2) ? field_10 + 2000 : field_10
Date.new(year, field_9, field_8) if field_10.present? && field_9.present? && field_8.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end
@ -1599,13 +1592,15 @@ private
end end
def mrcdate def mrcdate
Date.new(field_35 + 2000, field_34, field_33) if field_35.present? && field_34.present? && field_33.present? year = field_35.to_s.strip.length.between?(1, 2) ? field_35 + 2000 : field_35
Date.new(year, field_34, field_33) if field_35.present? && field_34.present? && field_33.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end
def voiddate def voiddate
Date.new(field_32 + 2000, field_31, field_30) if field_32.present? && field_31.present? && field_30.present? year = field_32.to_s.strip.length.between?(1, 2) ? field_32 + 2000 : field_32
Date.new(year, field_31, field_30) if field_32.present? && field_31.present? && field_30.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end

6
app/services/bulk_upload/sales/year2023/csv_parser.rb

@ -111,9 +111,11 @@ private
def first_record_start_date def first_record_start_date
if with_headers? if with_headers?
Date.new(row_parsers.first.field_5.to_i + 2000, row_parsers.first.field_4.to_i, row_parsers.first.field_3.to_i) year = row_parsers.first.field_5.to_s.strip.length.between?(1, 2) ? row_parsers.first.field_5.to_i + 2000 : row_parsers.first.field_5.to_i
Date.new(year, row_parsers.first.field_4.to_i, row_parsers.first.field_3.to_i)
else else
Date.new(rows.first[3].to_i + 2000, rows.first[2].to_i, rows.first[1].to_i) year = rows.first[3].to_s.strip.length.between?(1, 2) ? rows.first[3].to_i + 2000 : rows.first[3].to_i
Date.new(year, rows.first[2].to_i, rows.first[1].to_i)
end end
end end
end end

13
app/services/bulk_upload/sales/year2023/row_parser.rb

@ -328,8 +328,8 @@ class BulkUpload::Sales::Year2023::RowParser
category: :setup, category: :setup,
}, },
format: { format: {
with: /\A\d{2}\z/, with: /\A(\d{2}|\d{4})\z/,
message: I18n.t("validations.setup.saledate.year_not_two_digits"), message: I18n.t("validations.setup.saledate.year_not_two_or_four_digits"),
category: :setup, category: :setup,
if: proc { field_5.present? }, if: proc { field_5.present? },
}, on: :after_log }, on: :after_log
@ -954,19 +954,22 @@ private
end end
def saledate def saledate
Date.new(field_5 + 2000, field_4, field_3) if field_5.present? && field_4.present? && field_3.present? year = field_5.to_s.strip.length.between?(1, 2) ? field_5 + 2000 : field_5
Date.new(year, field_4, field_3) if field_5.present? && field_4.present? && field_3.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end
def hodate def hodate
Date.new(field_97 + 2000, field_96, field_95) if field_97.present? && field_96.present? && field_95.present? year = field_97.to_s.strip.length.between?(1, 2) ? field_97 + 2000 : field_97
Date.new(year, field_96, field_95) if field_97.present? && field_96.present? && field_95.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end
def exdate def exdate
Date.new(field_94 + 2000, field_93, field_92) if field_94.present? && field_93.present? && field_92.present? year = field_94.to_s.strip.length.between?(1, 2) ? field_94 + 2000 : field_94
Date.new(year, field_93, field_92) if field_94.present? && field_93.present? && field_92.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end

6
app/services/bulk_upload/sales/year2024/csv_parser.rb

@ -114,9 +114,11 @@ private
def first_record_start_date def first_record_start_date
if with_headers? if with_headers?
Date.new(row_parsers.first.field_6.to_i + 2000, row_parsers.first.field_5.to_i, row_parsers.first.field_4.to_i) year = row_parsers.first.field_6.to_s.strip.length.between?(1, 2) ? row_parsers.first.field_6.to_i + 2000 : row_parsers.first.field_6.to_i
Date.new(year, row_parsers.first.field_5.to_i, row_parsers.first.field_4.to_i)
else else
Date.new(rows.first[5].to_i + 2000, rows.first[4].to_i, rows.first[3].to_i) year = rows.first[5].to_s.strip.length.between?(1, 2) ? rows.first[5].to_i + 2000 : rows.first[5].to_i
Date.new(year, rows.first[4].to_i, rows.first[3].to_i)
end end
end end
end end

13
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -320,8 +320,8 @@ class BulkUpload::Sales::Year2024::RowParser
category: :setup, category: :setup,
}, },
format: { format: {
with: /\A\d{2}\z/, with: /\A(\d{2}|\d{4})\z/,
message: I18n.t("validations.setup.saledate.year_not_two_digits"), message: I18n.t("validations.setup.saledate.year_not_two_or_four_digits"),
category: :setup, category: :setup,
if: proc { field_6.present? }, if: proc { field_6.present? },
}, on: :after_log }, on: :after_log
@ -994,19 +994,22 @@ private
end end
def saledate def saledate
Date.new(field_6 + 2000, field_5, field_4) if field_6.present? && field_5.present? && field_4.present? year = field_6.to_s.strip.length.between?(1, 2) ? field_6 + 2000 : field_6
Date.new(year, field_5, field_4) if field_6.present? && field_5.present? && field_4.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end
def hodate def hodate
Date.new(field_96 + 2000, field_95, field_94) if field_96.present? && field_95.present? && field_94.present? year = field_96.to_s.strip.length.between?(1, 2) ? field_96 + 2000 : field_96
Date.new(year, field_95, field_94) if field_96.present? && field_95.present? && field_94.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end
def exdate def exdate
Date.new(field_93 + 2000, field_92, field_91) if field_93.present? && field_92.present? && field_91.present? year = field_93.to_s.strip.length.between?(1, 2) ? field_93 + 2000 : field_93
Date.new(year, field_92, field_91) if field_93.present? && field_92.present? && field_91.present?
rescue Date::Error rescue Date::Error
Date.new Date.new
end end

4
config/locales/en.yml

@ -284,7 +284,7 @@ en:
intermediate_rent_product_name: intermediate_rent_product_name:
blank: "Enter name of other intermediate rent product." blank: "Enter name of other intermediate rent product."
saledate: saledate:
year_not_two_digits: "Sale completion year must be 2 digits." year_not_two_or_four_digits: "Sale completion year must be 2 or 4 digits."
type: type:
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}% for this shared ownership type." percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}% for this shared ownership type."
@ -297,7 +297,7 @@ en:
before_scheme_end_date: "The tenancy start date must be before the end date for this supported housing scheme." 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_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." 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." year_not_two_or_four_digits: "Tenancy start year must be 2 or 4 digits."
ten_years_after_void_date: "Enter a tenancy start date that is no more than 10 years after the void date." ten_years_after_void_date: "Enter a tenancy start date that is no more than 10 years after the void date."
ten_years_after_mrc_date: "Enter a tenancy start date that is no more than 10 years after the major repairs completion date." ten_years_after_mrc_date: "Enter a tenancy start date that is no more than 10 years after the major repairs completion date."
invalid_merged_organisations_start_date: invalid_merged_organisations_start_date:

34
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -1476,11 +1476,21 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
context "when field_9 is 4 digits instead of 2" do context "when field_9 is 4 digits instead of 2" do
let(:attributes) { { bulk_upload:, field_9: "2022" } } let(:attributes) { setup_section_params.merge({ bulk_upload:, field_9: "2023", field_8: "12", field_7: "1" }) }
it "correctly sets the date" do
parser.valid?
expect(parser.errors[:field_9]).to be_empty
expect(parser.log.startdate).to eq(Date.new(2023, 12, 1))
end
end
context "when field_9 is not 4 or 2 digits" do
let(:attributes) { { bulk_upload:, field_9: "202" } }
it "returns an error" do it "returns an error" do
parser.valid? parser.valid?
expect(parser.errors[:field_9]).to include("Tenancy start year must be 2 digits.") expect(parser.errors[:field_9]).to include("Tenancy start year must be 2 or 4 digits.")
end end
end end
@ -2546,6 +2556,14 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
end end
context "when valid (4 digit year)" do
let(:attributes) { { bulk_upload:, field_36: "13", field_37: "12", field_38: "2022" } }
it "sets value given" do
expect(parser.log.mrcdate).to eq(Date.new(2022, 12, 13))
end
end
context "when invalid" do context "when invalid" do
let(:attributes) { { bulk_upload:, field_36: "13", field_37: "13", field_38: "22" } } let(:attributes) { { bulk_upload:, field_36: "13", field_37: "13", field_38: "22" } }
@ -2582,6 +2600,14 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
end end
context "when valid (4 digit year)" do
let(:attributes) { { bulk_upload:, field_33: "13", field_34: "12", field_35: "2022" } }
it "sets value given" do
expect(parser.log.voiddate).to eq(Date.new(2022, 12, 13))
end
end
context "when invalid" do context "when invalid" do
let(:attributes) { { bulk_upload:, field_33: "13", field_34: "13", field_35: "22" } } let(:attributes) { { bulk_upload:, field_33: "13", field_34: "13", field_35: "22" } }
@ -2824,12 +2850,12 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
end end
describe "#start_date" do describe "#startdate" do
context "when year of 9 is passed to represent 2009" do context "when year of 9 is passed to represent 2009" do
let(:attributes) { { bulk_upload:, field_7: "1", field_8: "1", field_9: "9" } } let(:attributes) { { bulk_upload:, field_7: "1", field_8: "1", field_9: "9" } }
it "uses the year 2009" do it "uses the year 2009" do
expect(parser.send(:start_date)).to eql(Date.new(2009, 1, 1)) expect(parser.send(:startdate)).to eql(Date.new(2009, 1, 1))
end end
end end
end end

34
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -1303,11 +1303,21 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when field_10 is 4 digits instead of 2" do context "when field_10 is 4 digits instead of 2" do
let(:attributes) { { bulk_upload:, field_10: "2023" } } let(:attributes) { setup_section_params.merge({ bulk_upload:, field_10: "2024", field_9: "4", field_8: "5" }) }
it "correctly sets the date" do
parser.valid?
expect(parser.errors[:field_10]).to be_empty
expect(parser.log.startdate).to eq(Time.zone.local(2024, 4, 5))
end
end
context "when field_10 is not 4 or 2 digits" do
let(:attributes) { { bulk_upload:, field_10: "204" } }
it "returns an error" do it "returns an error" do
parser.valid? parser.valid?
expect(parser.errors[:field_10]).to include("Tenancy start year must be 2 digits.") expect(parser.errors[:field_10]).to include("Tenancy start year must be 2 or 4 digits.")
end end
end end
@ -2659,6 +2669,14 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
end end
context "when valid (4 digit year)" do
let(:attributes) { { bulk_upload:, field_33: "13", field_34: "12", field_35: "2022" } }
it "sets value given" do
expect(parser.log.mrcdate).to eq(Date.new(2022, 12, 13))
end
end
context "when invalid" do context "when invalid" do
let(:attributes) { { bulk_upload:, field_33: "13", field_34: "13", field_35: "22" } } let(:attributes) { { bulk_upload:, field_33: "13", field_34: "13", field_35: "22" } }
@ -2695,6 +2713,14 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
end end
context "when valid (4 digit year)" do
let(:attributes) { { bulk_upload:, field_30: "13", field_31: "12", field_32: "2022" } }
it "sets value given" do
expect(parser.log.voiddate).to eq(Date.new(2022, 12, 13))
end
end
context "when invalid" do context "when invalid" do
let(:attributes) { { bulk_upload:, field_30: "13", field_31: "13", field_32: "22" } } let(:attributes) { { bulk_upload:, field_30: "13", field_31: "13", field_32: "22" } }
@ -2945,12 +2971,12 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
end end
describe "#start_date" do describe "#startdate" do
context "when year of 9 is passed to represent 2009" do context "when year of 9 is passed to represent 2009" do
let(:attributes) { { bulk_upload:, field_8: "1", field_9: "1", field_10: "9" } } let(:attributes) { { bulk_upload:, field_8: "1", field_9: "1", field_10: "9" } }
it "uses the year 2009" do it "uses the year 2009" do
expect(parser.send(:start_date)).to eql(Date.new(2009, 1, 1)) expect(parser.send(:startdate)).to eql(Date.new(2009, 1, 1))
end end
end end
end end

19
spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

@ -88,10 +88,10 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
field_90: "1", field_90: "1",
field_92: "30", field_92: "30",
field_93: "3", field_93: "3",
field_94: "22", field_94: "2022",
field_95: "24", field_95: "24",
field_96: "3", field_96: "3",
field_97: "22", field_97: "2022",
field_98: "3", field_98: "3",
field_99: "1", field_99: "1",
field_100: "1", field_100: "1",
@ -594,10 +594,21 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end end
context "when field 5 is 4 digits instead of 2" do context "when field 5 is 4 digits instead of 2" do
let(:attributes) { setup_section_params.merge({ bulk_upload:, field_5: "2022" }) } let(:attributes) { setup_section_params.merge({ bulk_upload:, field_5: "2023", field_4: "4", field_3: "3" }) }
it "correctly sets the date" do
parser.valid?
expect(parser.errors.where(:field_5, category: :setup)).to be_empty
expect(parser.log.saledate).to eq(Time.zone.local(2023, 4, 3))
end
end
context "when field 5 is not 2 or 4 digits" do
let(:attributes) { setup_section_params.merge({ bulk_upload:, field_5: "202" }) }
it "returns a setup error" do it "returns a setup error" do
expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to include("Sale completion year must be 2 digits.") parser.valid?
expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to include("Sale completion year must be 2 or 4 digits.")
end end
end end

20
spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

@ -95,10 +95,10 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
field_89: "1", field_89: "1",
field_91: "30", field_91: "30",
field_92: "3", field_92: "3",
field_93: "22", field_93: "2022",
field_94: "24", field_94: "24",
field_95: "3", field_95: "3",
field_96: "22", field_96: "2022",
field_97: "3", field_97: "3",
field_98: "1", field_98: "1",
field_99: "1", field_99: "1",
@ -721,12 +721,22 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end end
end end
context "when field 5 is 4 digits instead of 2" do context "when field 6 is 4 digits instead of 2" do
let(:attributes) { setup_section_params.merge({ bulk_upload:, field_6: "2023" }) } let(:attributes) { setup_section_params.merge({ bulk_upload:, field_6: "2024" }) }
it "correctly sets the date" do
parser.valid?
expect(parser.errors.where(:field_6, category: :setup)).to be_empty
expect(parser.log.saledate).to eq(Time.zone.local(2024, 5, 1))
end
end
context "when field 5 is not 2 or 4 digits" do
let(:attributes) { setup_section_params.merge({ bulk_upload:, field_6: "202" }) }
it "returns a setup error" do it "returns a setup error" do
parser.valid? parser.valid?
expect(parser.errors.where(:field_6, category: :setup).map(&:message)).to include("Sale completion year must be 2 digits.") expect(parser.errors.where(:field_6, category: :setup).map(&:message)).to include("Sale completion year must be 2 or 4 digits.")
end end
end end

Loading…
Cancel
Save