Browse Source

Allow mortgageused don't know if stairowned 100

pull/2310/head
Kat 2 years ago
parent
commit
dfc9f2d37d
  1. 9
      app/services/bulk_upload/sales/year2023/row_parser.rb
  2. 24
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

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

@ -425,6 +425,14 @@ class BulkUpload::Sales::Year2023::RowParser
}, },
on: :before_log 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, validates :field_13,
presence: { presence: {
message: I18n.t("validations.not_answered", question: "buyers living in property"), message: I18n.t("validations.not_answered", question: "buyers living in property"),
@ -1336,7 +1344,6 @@ private
def validate_mortgageused def validate_mortgageused
if mortgageused.present? && mortgageused.to_i != 1 && mortgageused.to_i != 2 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_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? 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 end

24
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_119]).to be_empty
expect(parser.errors[:field_128]).to be_empty expect(parser.errors[:field_128]).to be_empty
end 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 end
describe "#field_119" do describe "#field_119" do

Loading…
Cancel
Save