Browse Source

manually validate setup fields

pull/1633/head
Phil Lee 3 years ago
parent
commit
58eb2e7a11
  1. 26
      app/services/bulk_upload/sales/year2023/row_parser.rb
  2. 30
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

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

@ -340,6 +340,14 @@ class BulkUpload::Sales::Year2023::RowParser
},
on: :after_log
validates :field_8,
inclusion: {
in: [2, 30, 18, 16, 24, 28, 31, 32],
if: proc { field_8.present? },
category: :setup,
},
on: :before_log
validates :field_8,
presence: {
message: I18n.t("validations.not_answered", question: "shared ownership type"),
@ -348,6 +356,14 @@ class BulkUpload::Sales::Year2023::RowParser
},
on: :after_log
validates :field_9,
inclusion: {
in: [8, 14, 27, 9, 29, 21, 22],
if: proc { field_9.present? },
category: :setup,
},
on: :before_log
validates :field_9,
presence: {
message: I18n.t("validations.not_answered", question: "shared ownership type"),
@ -356,6 +372,14 @@ class BulkUpload::Sales::Year2023::RowParser
},
on: :after_log
validates :field_10,
inclusion: {
in: [10, 12],
if: proc { field_10.present? },
category: :setup,
},
on: :before_log
validates :field_10,
presence: {
message: I18n.t("validations.not_answered", question: "shared ownership type"),
@ -1156,6 +1180,8 @@ private
log.attributes.each do |question_id, _v|
question = log.form.get_question(question_id, log)
next if question_id == "type"
next unless question&.type == "radio"
next if log[question_id].blank? || question.answer_options.key?(log[question_id].to_s) || !question.page.routed_to?(log, nil)

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

@ -575,6 +575,36 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end
end
describe "#field_8" do # type for shared ownership sale
context "when an invalid option" do
let(:attributes) { setup_section_params.merge({ field_8: "100" }) }
it "returns setup error" do
expect(parser.errors.where(:field_8, category: :setup)).to be_present
end
end
end
describe "#field_9" do # type for discounted sale
context "when an invalid option" do
let(:attributes) { setup_section_params.merge({ field_9: "100" }) }
it "returns setup error" do
expect(parser.errors.where(:field_9, category: :setup)).to be_present
end
end
end
describe "#field_10" do # type for outright sale
context "when an invalid option" do
let(:attributes) { setup_section_params.merge({ field_10: "100" }) }
it "returns setup error" do
expect(parser.errors.where(:field_10, category: :setup)).to be_present
end
end
end
describe "#field_19" do # UPRN
context "when UPRN known and lookup found" do
let(:attributes) { setup_section_params.merge({ field_19: "100023336956" }) }

Loading…
Cancel
Save