Browse Source

validate field_12 inclusion

pull/1633/head
Phil Lee 3 years ago
parent
commit
ba3878ac1a
  1. 18
      app/services/bulk_upload/sales/year2023/row_parser.rb
  2. 2
      config/locales/en.yml
  3. 11
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

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

@ -396,22 +396,32 @@ class BulkUpload::Sales::Year2023::RowParser
}, },
on: :after_log on: :after_log
validates :field_13, validates :field_12,
inclusion: {
in: [1, 2],
if: proc { outright_sale? && field_12.present? },
category: :setup,
question: QUESTIONS[:field_12].downcase,
},
on: :before_log
validates :field_12,
presence: { presence: {
message: I18n.t("validations.not_answered", question: "will the buyers live in the property"), message: I18n.t("validations.not_answered", question: "company buyer"),
category: :setup, category: :setup,
if: :outright_sale?, if: :outright_sale?,
}, },
on: :after_log on: :after_log
validates :field_12, validates :field_13,
presence: { presence: {
message: I18n.t("validations.not_answered", question: "company buyer"), message: I18n.t("validations.not_answered", question: "will the buyers live in the property"),
category: :setup, category: :setup,
if: :outright_sale?, if: :outright_sale?,
}, },
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"),

2
config/locales/en.yml

@ -41,6 +41,8 @@ en:
activemodel: activemodel:
errors: errors:
models: models:
bulk_upload/sales/year2023/row_parser:
inclusion: Enter a valid value for %{question}
bulk_upload/lettings/validator: bulk_upload/lettings/validator:
attributes: attributes:
base: base:

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

@ -615,6 +615,17 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end end
end end
describe "#field_12" do # buyer a company?
context "when an invalid option" do
let(:attributes) { setup_section_params.merge({ field_7: "3", field_12: "100" }) }
it "returns setup error" do
expect(parser.errors.where(:field_12).map(&:message)).to eql(["Enter a valid value for is the buyer a company?"])
expect(parser.errors.where(:field_12, 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