diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 88815a089..925195ec3 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -425,6 +425,14 @@ class BulkUpload::Sales::Year2023::RowParser }, on: :before_log + validates :field_105, + inclusion: { + in: [1, 2], + if: proc { field_89.present? && field_89 != 100 && shared_ownership? }, + question: QUESTIONS[:field_105], + }, + on: :before_log + validates :field_13, presence: { message: I18n.t("validations.not_answered", question: "buyers living in property"), @@ -1336,7 +1344,6 @@ private def validate_mortgageused if mortgageused.present? && mortgageused.to_i != 1 && mortgageused.to_i != 2 - errors.add(:field_105, I18n.t("validations.invalid_option", question: "Was a mortgage used for the purchase of this property? - Shared ownership")) if shared_ownership? errors.add(:field_119, I18n.t("validations.invalid_option", question: "Was a mortgage used for the purchase of this property? - Discounted ownership")) if discounted_ownership? errors.add(:field_128, I18n.t("validations.invalid_option", question: "Was a mortgage used for the purchase of this property? - Outright sale")) if outright_sale? end diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index be8a401cb..b9f95b181 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -1029,6 +1029,30 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do expect(parser.errors[:field_119]).to be_empty expect(parser.errors[:field_128]).to be_empty end + + context "when invalid value" do + let(:attributes) { setup_section_params.merge(field_105: "4") } + + it "returns correct errors" do + expect(parser.errors[:field_105]).to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + end + end + + context "when value is 3 and stairowned is not 100" do + let(:attributes) { setup_section_params.merge(field_105: "3", field_87: "1", field_88: "50", field_89: "99", field_111: nil) } + + it "returns correct errors" do + expect(parser.errors[:field_105]).to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + end + end + + context "when value is 3 and stairowned is not answered" do + let(:attributes) { setup_section_params.merge(field_105: "3", field_87: "1", field_88: "50", field_89: nil, field_111: nil) } + + it "does not add errors" do + expect(parser.errors[:field_105]).not_to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Shared ownership") + end + end end describe "#field_119" do