diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index 9fda600b5..3c48bc141 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -337,6 +337,30 @@ class BulkUpload::Lettings::Year2023::RowParser }, on: :after_log + validates :field_116, + inclusion: { + in: [1, 2], + message: I18n.t("validations.invalid_option", question: "was the letting made under the Choice-Based Lettings (CBL)"), + if: -> { field_116.present? }, + }, + on: :after_log + + validates :field_117, + inclusion: { + in: [1, 2], + message: I18n.t("validations.invalid_option", question: "was the letting made under the Common Allocation Policy (CAP)"), + if: -> { field_117.present? }, + }, + on: :after_log + + validates :field_118, + inclusion: { + in: [1, 2], + message: I18n.t("validations.invalid_option", question: "was the letting made under the Common Housing Register (CHR)"), + if: -> { field_118.present? }, + }, + on: :after_log + validates :field_46, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 1 must be a number or the letter R" }, on: :after_log validates :field_52, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 2 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(2).zero? } validates :field_56, format: { with: /\A\d{1,3}\z|\AR\z/, message: "Age of person 3 must be a number or the letter R" }, on: :after_log, if: proc { details_known?(3).zero? } diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 7435a3d74..a5dd076aa 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -1997,6 +1997,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do expect(parser.log.cbl).to be(0) end end + + context "when field_116 is not a permitted value" do + let(:attributes) { { bulk_upload:, field_116: 3 } } + + it "adds an error" do + parser.valid? + expect(parser.errors[:field_116]).to include("Enter a valid value for was the letting made under the Choice-Based Lettings (CBL)") + end + end end describe "#chr" do @@ -2015,6 +2024,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do expect(parser.log.chr).to be(0) end end + + context "when field_118 is not a permitted value" do + let(:attributes) { { bulk_upload:, field_118: 3 } } + + it "adds an error" do + parser.valid? + expect(parser.errors[:field_118]).to include("Enter a valid value for was the letting made under the Common Housing Register (CHR)") + end + end end describe "#cap" do @@ -2033,6 +2051,15 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do expect(parser.log.cap).to be(0) end end + + context "when field_117 is not a permitted value" do + let(:attributes) { { bulk_upload:, field_117: 3 } } + + it "adds an error" do + parser.valid? + expect(parser.errors[:field_117]).to include("Enter a valid value for was the letting made under the Common Allocation Policy (CAP)") + end + end end describe "#letting_allocation_unknown" do