Browse Source

Add custom ecstat BU errors

pull/2256/head
Kat 2 years ago
parent
commit
c50aa1fbb0
  1. 19
      app/services/bulk_upload/sales/year2024/row_parser.rb
  2. 1
      config/locales/en.yml
  3. 55
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

19
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_buyer1_economic_status, on: :before_log
validate :validate_address_option_found, on: :after_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_nulls, on: :after_log
validate :validate_valid_radio_option, on: :before_log validate :validate_valid_radio_option, on: :before_log
@ -1350,7 +1351,23 @@ private
def validate_buyer1_economic_status def validate_buyer1_economic_status
if field_35 == 9 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
end end

1
config/locales/en.yml

@ -486,6 +486,7 @@ en:
not_child_16_19: not_child_16_19:
cannot_be_student: "Person cannot be a student if they are aged 16-19 but are not a child" 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_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: relat:
child_under_16_sales: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16" 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" child_under_16_lettings: "Answer cannot be ‘partner’ as you told us person %{person_num}'s age is under 16"

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

@ -948,13 +948,62 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end end
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 describe "field_35" do # ecstat1
context "when buyer 1 is marked as a child" do context "when buyer 1 has no age but has ecstat as child" do
let(:attributes) { valid_attributes.merge({ field_35: "9" }) } 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 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_35]).to include validation_message
expect(parser.errors[:field_31]).to include validation_message
end end
end end
end end

Loading…
Cancel
Save