Browse Source

CLDC-2313 add bulk upload validation buyer 1 cannot be child (#1634)

* add a bespoke validation to the row parser
when buyer 1 is uploaded with working situation child, this should be validated with a custom message.
a test for this case was also created

* replicate the work from the last commit for the 2023 row parser and associated test file

* lint correction remove blank lines
pull/1648/head
Arthur Campbell 2 years ago committed by GitHub
parent
commit
3b83614ab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      app/services/bulk_upload/sales/year2022/row_parser.rb
  2. 9
      app/services/bulk_upload/sales/year2023/row_parser.rb
  3. 19
      spec/services/bulk_upload/sales/year2022/row_parser_spec.rb
  4. 19
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

13
app/services/bulk_upload/sales/year2022/row_parser.rb

@ -274,6 +274,7 @@ class BulkUpload::Sales::Year2022::RowParser
validates :field_114, presence: { message: I18n.t("validations.not_answered", question: "company buyer") }, if: :outright_sale?, on: :after_log validates :field_114, presence: { message: I18n.t("validations.not_answered", question: "company buyer") }, if: :outright_sale?, on: :after_log
validates :field_109, presence: { message: I18n.t("validations.not_answered", question: "more than 2 buyers") }, if: :joint_purchase?, on: :after_log validates :field_109, presence: { message: I18n.t("validations.not_answered", question: "more than 2 buyers") }, if: :joint_purchase?, on: :after_log
validate :validate_buyer1_economic_status, on: :before_log
validate :validate_nulls, on: :after_log validate :validate_nulls, on: :after_log
validate :validate_valid_radio_option, on: :before_log validate :validate_valid_radio_option, on: :before_log
@ -812,7 +813,7 @@ private
end end
def owning_organisation def owning_organisation
Organisation.find_by_id_on_multiple_fields(field_92) @owning_organisation ||= Organisation.find_by_id_on_multiple_fields(field_92)
end end
def created_by def created_by
@ -946,7 +947,7 @@ private
end end
else else
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } if errors.none? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase)) errors.add(field, I18n.t("validations.not_answered", question: question.check_answer_label&.downcase))
end end
end end
@ -971,7 +972,7 @@ private
end end
else else
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } if errors.none? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.invalid_option", question: QUESTIONS[field])) errors.add(field, I18n.t("validations.invalid_option", question: QUESTIONS[field]))
end end
end end
@ -1021,4 +1022,10 @@ private
errors.add(:field_1, error_message) # Purchaser code errors.add(:field_1, error_message) # Purchaser code
end end
end end
def validate_buyer1_economic_status
if field_24 == 9
errors.add(:field_24, "Buyer 1 cannot be a child under 16")
end
end
end end

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

@ -396,6 +396,7 @@ class BulkUpload::Sales::Year2023::RowParser
}, },
on: :after_log on: :after_log
validate :validate_buyer1_economic_status, on: :before_log
validate :validate_nulls, on: :after_log validate :validate_nulls, on: :after_log
validate :validate_valid_radio_option, on: :before_log validate :validate_valid_radio_option, on: :before_log
@ -1019,7 +1020,7 @@ private
end end
def owning_organisation def owning_organisation
Organisation.find_by_id_on_multiple_fields(field_1) @owning_organisation ||= Organisation.find_by_id_on_multiple_fields(field_1)
end end
def created_by def created_by
@ -1219,4 +1220,10 @@ private
end end
end end
end end
def validate_buyer1_economic_status
if field_35 == 9
errors.add(:field_35, "Buyer 1 cannot be a child under 16")
end
end
end end

19
spec/services/bulk_upload/sales/year2022/row_parser_spec.rb

@ -107,14 +107,6 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
} }
end end
around do |example|
FormHandler.instance.use_real_forms!
example.run
FormHandler.instance.use_fake_forms!
end
describe "#blank_row?" do describe "#blank_row?" do
context "when a new object" do context "when a new object" do
it "returns true" do it "returns true" do
@ -469,6 +461,17 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
end end
end end
describe "field_24" do # ecstat1
context "when buyer 1 is marked as a child" do
let(:attributes) { valid_attributes.merge({ field_24: 9 }) }
it "a custom validation is applied" do
validation_message = "Buyer 1 cannot be a child under 16"
expect(parser.errors[:field_24]).to include validation_message
end
end
end
describe "fields 2, 3, 4 => saledate" do describe "fields 2, 3, 4 => saledate" do
context "when all of these fields are blank" do context "when all of these fields are blank" do
let(:attributes) { setup_section_params.merge({ field_2: nil, field_3: nil, field_4: nil }) } let(:attributes) { setup_section_params.merge({ field_2: nil, field_3: nil, field_4: nil }) }

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

@ -110,14 +110,6 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
} }
end end
around do |example|
FormHandler.instance.use_real_forms!
example.run
FormHandler.instance.use_fake_forms!
end
describe "#blank_row?" do describe "#blank_row?" do
context "when a new object" do context "when a new object" do
it "returns true" do it "returns true" do
@ -705,6 +697,17 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end end
end end
describe "field_35" do # ecstat1
context "when buyer 1 is marked as a child" do
let(:attributes) { valid_attributes.merge({ field_35: "9" }) }
it "a custom validation is applied" do
validation_message = "Buyer 1 cannot be a child under 16"
expect(parser.errors[:field_35]).to include validation_message
end
end
end
describe "#field_36" do # will buyer1 live in property? describe "#field_36" do # will buyer1 live in property?
context "when not a possible value" do context "when not a possible value" do
let(:attributes) { valid_attributes.merge({ field_36: "3" }) } let(:attributes) { valid_attributes.merge({ field_36: "3" }) }

Loading…
Cancel
Save