From c50aa1fbb053e9f3b8a1f8c5fc2dc49967dfbba0 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 13 Mar 2024 09:17:41 +0000 Subject: [PATCH] Add custom ecstat BU errors --- .../bulk_upload/sales/year2024/row_parser.rb | 19 ++++++- config/locales/en.yml | 1 + .../sales/year2024/row_parser_spec.rb | 55 ++++++++++++++++++- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/app/services/bulk_upload/sales/year2024/row_parser.rb b/app/services/bulk_upload/sales/year2024/row_parser.rb index 928060dfa..41a2aa9a4 100644 --- a/app/services/bulk_upload/sales/year2024/row_parser.rb +++ b/app/services/bulk_upload/sales/year2024/row_parser.rb @@ -443,6 +443,7 @@ class BulkUpload::Sales::Year2024::RowParser validate :validate_buyer1_economic_status, on: :before_log validate :validate_address_option_found, on: :after_log + validate :validate_buyer2_economic_status, on: :before_log validate :validate_nulls, on: :after_log validate :validate_valid_radio_option, on: :before_log @@ -1350,7 +1351,23 @@ private def validate_buyer1_economic_status if field_35 == 9 - errors.add(:field_35, "Buyer 1 cannot be a child under 16") + if field_31.present? && field_31.to_i >= 16 + errors.add(:field_35, I18n.t("validations.household.ecstat.buyer_cannot_be_over_16_and_child", buyer_index: "1")) + errors.add(:field_31, I18n.t("validations.household.ecstat.buyer_cannot_be_over_16_and_child", buyer_index: "1")) + else + errors.add(:field_35, I18n.t("validations.household.ecstat.buyer_cannot_be_child", buyer_index: "1")) + end + end + end + + def validate_buyer2_economic_status + 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")) + errors.add(:field_38, I18n.t("validations.household.ecstat.buyer_cannot_be_over_16_and_child", buyer_index: "2")) + else + errors.add(:field_42, I18n.t("validations.household.ecstat.buyer_cannot_be_child", buyer_index: "2")) + end end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 8d9502b23..736aff310 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -486,6 +486,7 @@ en: not_child_16_19: cannot_be_student: "Person cannot be a student if they are aged 16-19 but are not a child" buyer_cannot_be_child: "Buyer %{buyer_index} cannot have a working situation of child under 16" + buyer_cannot_be_over_16_and_child: "Buyer %{buyer_index}'s age cannot be 16 or over if their working situation is child under 16" relat: child_under_16_sales: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16" child_under_16_lettings: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16" 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 ea0ea386e..2396f19a3 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -948,13 +948,62 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do end end + describe "field_42" do # ecstat1 + context "when buyer 2 has no age but has ecstat as child" do + let(:attributes) { valid_attributes.merge({ field_38: nil, field_42: "9" }) } + + it "a custom validation is applied" do + validation_message = "Buyer 2 cannot have a working situation of child under 16" + expect(parser.errors[:field_42]).to include validation_message + end + end + + context "when buyer 2 is under 16" do + let(:attributes) { valid_attributes.merge({ field_38: "9" }) } + + it "a custom validation is applied" do + validation_message = "Buyer 2’s age must be between 16 and 110" + expect(parser.errors[:field_38]).to include validation_message + end + end + + context "when buyer 2 is over 16 but has ecstat as child" do + let(:attributes) { valid_attributes.merge({ field_38: "17", field_42: "9" }) } + + it "a custom validation is applied" do + validation_message = "Buyer 2's age cannot be 16 or over if their working situation is child under 16" + expect(parser.errors[:field_42]).to include validation_message + expect(parser.errors[:field_38]).to include validation_message + 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" }) } + context "when buyer 1 has no age but has ecstat as child" do + let(:attributes) { valid_attributes.merge({ field_31: nil, field_35: "9" }) } + + it "a custom validation is applied" do + validation_message = "Buyer 1 cannot have a working situation of child under 16" + expect(parser.errors[:field_35]).to include validation_message + end + end + + context "when buyer 1 is under 16" do + let(:attributes) { valid_attributes.merge({ field_31: "9" }) } + + it "a custom validation is applied" do + validation_message = "Buyer 1’s age must be between 16 and 110" + expect(parser.errors[:field_31]).to include validation_message + end + end + + context "when buyer 1 is over 16 but has ecstat as child" do + let(:attributes) { valid_attributes.merge({ field_31: "17", field_35: "9" }) } it "a custom validation is applied" do - validation_message = "Buyer 1 cannot be a child under 16" + validation_message = "Buyer 1's age cannot be 16 or over if their working situation is child under 16" expect(parser.errors[:field_35]).to include validation_message + expect(parser.errors[:field_31]).to include validation_message end end end