diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index 682464331..ab2819389 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -451,6 +451,7 @@ class BulkUpload::Sales::Year2024::RowParser validate :validate_buyer1_economic_status, on: :before_log validate :validate_address_option_found, on: :after_log + validate :validate_mortgageused, on: :before_log validate :validate_nulls, on: :after_log validate :validate_valid_radio_option, on: :before_log @@ -1377,4 +1378,10 @@ private def valid_nationality_options %w[0] + GlobalConstants::COUNTRIES_ANSWER_OPTIONS.keys # 0 is "Prefers not to say" end + + def validate_mortgageused + if discounted_ownership? && mortgageused.present? && mortgageused.to_i != 1 && mortgageused.to_i != 2 + errors.add(:field_117, I18n.t("validations.invalid_option", question: "Was a mortgage used for the purchase of this property? - Discounted ownership")) + end + end end diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index df6ed7764..73d804689 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -1017,14 +1017,6 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end - context "when it's not shared ownership" do - let(:attributes) { setup_section_params.merge(field_8: "2", field_103: "3", field_86: "1", field_87: "50", field_88: "99", field_109: nil) } - - it "does not add errors" do - expect(parser.errors[:field_103]).not_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 100" do let(:attributes) { setup_section_params.merge(field_103: "3", field_86: "1", field_87: "50", field_88: "100", field_109: nil) } @@ -1039,6 +1031,14 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end describe "#field_117" do + let(:attributes) { valid_attributes.merge({ field_8: "2", field_117: "3" }) } + + it "does not allow 3 (don't know) as an option for discounted ownership" do + expect(parser.errors[:field_117]).to include("Enter a valid value for Was a mortgage used for the purchase of this property? - Discounted ownership") + expect(parser.errors[:field_103]).to be_empty + expect(parser.errors[:field_126]).to be_empty + end + context "when validate_discounted_ownership_value is triggered" do let(:attributes) { setup_section_params.merge(field_114: 100, field_123: 100, field_8: 2, field_10: 9, field_117: 2, field_116: 10) } @@ -1050,6 +1050,16 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end + describe "#field_126" do + let(:attributes) { valid_attributes.merge({ field_8: "3", field_126: "3" }) } + + it "allows 3 (don't know) as an option for outright sale" do + expect(parser.errors[:field_126]).to be_empty + expect(parser.errors[:field_103]).to be_empty + expect(parser.errors[:field_117]).to be_empty + end + end + describe "soft validations" do context "when soft validation is triggered" do let(:attributes) { valid_attributes.merge({ field_31: 22, field_35: 5 }) } @@ -1061,7 +1071,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do it "populates with correct error message" do expect(parser.errors.where(:field_31, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") - expect(parser.errors.where(:field_31, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") + expect(parser.errors.where(:field_35, category: :soft_validation).first.message).to eql("You told us this person is aged 22 years and retired.") end end end