Browse Source

CLDC-3460: Don't validate P2 not child in BU when not a joint purchase (#2431)

* CLDC-3460: Don't validate P2 not child in BU when not a joint purchase

* Fix joint purchase field numbers for 2023
pull/2438/head
Rachael Booth 7 months ago committed by GitHub
parent
commit
4cfdd967dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/services/bulk_upload/sales/year2023/row_parser.rb
  2. 6
      app/services/bulk_upload/sales/year2024/row_parser.rb
  3. 11
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

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

@ -627,11 +627,11 @@ private
end end
def joint_purchase? def joint_purchase?
field_116 == 1 field_14 == 1
end end
def joint_purchase_asked? def joint_purchase_asked?
shared_ownership? || discounted_ownership? || field_114 == 2 shared_ownership? || discounted_ownership? || field_12 == 2
end end
def field_mapping_for_errors def field_mapping_for_errors

6
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -635,11 +635,11 @@ private
end end
def joint_purchase? def joint_purchase?
field_114 == 1 field_15 == 1
end end
def joint_purchase_asked? def joint_purchase_asked?
shared_ownership? || discounted_ownership? || field_112 == 2 shared_ownership? || discounted_ownership? || field_13 == 2
end end
def field_mapping_for_errors def field_mapping_for_errors
@ -1450,6 +1450,8 @@ private
end end
def validate_buyer2_economic_status def validate_buyer2_economic_status
return unless joint_purchase?
if field_42 == 9 if field_42 == 9
if field_38.present? && field_38.to_i >= 16 if field_38.present? && field_38.to_i >= 16
errors.add(:field_42, I18n.t("validations.household.ecstat.buyer_cannot_be_over_16_and_child", buyer_index: "2")) errors.add(:field_42, I18n.t("validations.household.ecstat.buyer_cannot_be_over_16_and_child", buyer_index: "2"))

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

@ -1027,7 +1027,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end end
end end
describe "field_42" do # ecstat1 describe "field_42" do # ecstat2
context "when buyer 2 has no age but has ecstat as child" do context "when buyer 2 has no age but has ecstat as child" do
let(:attributes) { valid_attributes.merge({ field_38: nil, field_42: "9" }) } let(:attributes) { valid_attributes.merge({ field_38: nil, field_42: "9" }) }
@ -1055,6 +1055,15 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
expect(parser.errors[:field_38]).to include validation_message expect(parser.errors[:field_38]).to include validation_message
end end
end end
context "when person 2 a child but not a buyer" do
let(:attributes) { valid_attributes.merge({ field_15: 2, field_38: "10", field_42: "9" }) }
it "does not add errors to their age and ecstat fields" do
expect(parser.errors[:field_38]).to be_empty
expect(parser.errors[:field_42]).to be_empty
end
end
end end
describe "field_35" do # ecstat1 describe "field_35" do # ecstat1

Loading…
Cancel
Save