From 4cfdd967dc3dc68e2c54d27c3b5f16d996fba229 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Wed, 5 Jun 2024 14:14:46 +0100 Subject: [PATCH] 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 --- app/services/bulk_upload/sales/year2023/row_parser.rb | 4 ++-- app/services/bulk_upload/sales/year2024/row_parser.rb | 6 ++++-- .../bulk_upload/sales/year2024/row_parser_spec.rb | 11 ++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index 819ea3618..28e7f1e3b 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -627,11 +627,11 @@ private end def joint_purchase? - field_116 == 1 + field_14 == 1 end def joint_purchase_asked? - shared_ownership? || discounted_ownership? || field_114 == 2 + shared_ownership? || discounted_ownership? || field_12 == 2 end def field_mapping_for_errors diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index e5715b3bc..d85b5dfc2 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -635,11 +635,11 @@ private end def joint_purchase? - field_114 == 1 + field_15 == 1 end def joint_purchase_asked? - shared_ownership? || discounted_ownership? || field_112 == 2 + shared_ownership? || discounted_ownership? || field_13 == 2 end def field_mapping_for_errors @@ -1450,6 +1450,8 @@ private end def validate_buyer2_economic_status + return unless joint_purchase? + if field_42 == 9 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")) diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index 0ab21e1b0..fa2e1cdc9 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -1027,7 +1027,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do 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 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 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 describe "field_35" do # ecstat1