Browse Source

validate field_13 valid option

pull/1633/head
Phil Lee 3 years ago
parent
commit
38095d5b30
  1. 10
      app/services/bulk_upload/sales/year2023/row_parser.rb
  2. 11
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

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

@ -413,6 +413,15 @@ class BulkUpload::Sales::Year2023::RowParser
}, },
on: :after_log on: :after_log
validates :field_13,
inclusion: {
in: [1, 2],
if: proc { outright_sale? && field_13.present? },
category: :setup,
question: QUESTIONS[:field_13].downcase,
},
on: :before_log
validates :field_13, validates :field_13,
presence: { presence: {
message: I18n.t("validations.not_answered", question: "will the buyers live in the property"), message: I18n.t("validations.not_answered", question: "will the buyers live in the property"),
@ -421,7 +430,6 @@ class BulkUpload::Sales::Year2023::RowParser
}, },
on: :after_log on: :after_log
validates :field_14, validates :field_14,
presence: { presence: {
message: I18n.t("validations.not_answered", question: "joint purchase"), message: I18n.t("validations.not_answered", question: "joint purchase"),

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

@ -626,6 +626,17 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end end
end end
describe "#field_13" do # will buyers live in the property?
context "when an invalid option" do
let(:attributes) { setup_section_params.merge({ field_7: "3", field_13: "100" }) }
it "returns setup error" do
expect(parser.errors.where(:field_13).map(&:message)).to eql(["Enter a valid value for will the buyers live in the property?"])
expect(parser.errors.where(:field_13, category: :setup)).to be_present
end
end
end
describe "#field_14" do # joint purchase describe "#field_14" do # joint purchase
context "when an invalid option" do context "when an invalid option" do
let(:attributes) { setup_section_params.merge({ field_14: "100" }) } let(:attributes) { setup_section_params.merge({ field_14: "100" }) }

Loading…
Cancel
Save