Browse Source

field_11 must be present if field_10 == 12

pull/1633/head
Phil Lee 3 years ago
parent
commit
aedd1f22a6
  1. 8
      app/services/bulk_upload/sales/year2023/row_parser.rb
  2. 12
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

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

@ -388,6 +388,14 @@ class BulkUpload::Sales::Year2023::RowParser
}, },
on: :after_log on: :after_log
validates :field_11,
presence: {
message: I18n.t("validations.not_answered", question: "type of outright sale"),
category: :setup,
if: proc { field_10 == 12 },
},
on: :after_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"),

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

@ -340,7 +340,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
it "has errors on correct setup fields" do it "has errors on correct setup fields" do
errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute).sort errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute).sort
expect(errors).to eql(%i[field_1 field_13 field_14 field_3 field_4 field_5]) expect(errors).to eql(%i[field_1 field_11 field_13 field_14 field_3 field_4 field_5])
end end
end end
@ -605,6 +605,16 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end end
end end
describe "#field_11" do # type of other outright sale
context "when an invalid option" do
let(:attributes) { setup_section_params.merge({ field_10: "12", field_11: nil }) }
it "returns setup error" do
expect(parser.errors.where(:field_11, category: :setup)).to be_present
end
end
end
describe "#field_19" do # UPRN describe "#field_19" do # UPRN
context "when UPRN known and lookup found" do context "when UPRN known and lookup found" do
let(:attributes) { setup_section_params.merge({ field_19: "100023336956" }) } let(:attributes) { setup_section_params.merge({ field_19: "100023336956" }) }

Loading…
Cancel
Save