Browse Source

Add ecstat buyer validation

pull/2256/head
Kat 2 years ago
parent
commit
c8859dc8f7
  1. 7
      app/models/validations/sales/household_validations.rb
  2. 1
      config/locales/en.yml
  3. 51
      spec/models/validations/sales/household_validations_spec.rb

7
app/models/validations/sales/household_validations.rb

@ -107,6 +107,13 @@ module Validations::Sales::HouseholdValidations
end
end
def validate_buyer_not_child(record)
return unless record.saledate && record.form.start_year_after_2024?
record.errors.add "ecstat1", I18n.t("validations.household.ecstat.buyer_cannot_be_child", buyer_index: "1") if person_is_economic_child?(record.ecstat1)
record.errors.add "ecstat2", I18n.t("validations.household.ecstat.buyer_cannot_be_child", buyer_index: "2") if person_is_economic_child?(record.ecstat2) && record.joint_purchase?
end
private
def person_is_fulltime_student?(economic_status)

1
config/locales/en.yml

@ -485,6 +485,7 @@ en:
retired_female: "Answer cannot be ‘retired’ as the female tenant is under 60"
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"
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"

51
spec/models/validations/sales/household_validations_spec.rb

@ -446,4 +446,55 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end
end
end
describe "#validate_buyer_not_child" do
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) }
it "does not add an error if either buyer is a child" do
record.jointpur = 1
record.ecstat1 = 9
record.ecstat2 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat1"]).to be_empty
expect(record.errors["ecstat2"]).to be_empty
end
end
context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) }
it "validates buyer 1 isn't a child" do
record.ecstat1 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat1"])
.to include("Buyer 1 cannot have a working situation of child under 16")
end
it "validates buyer 2 isn't a child" do
record.jointpur = 1
record.ecstat2 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat2"])
.to include("Buyer 2 cannot have a working situation of child under 16")
end
it "allows person 2 to be a child" do
record.jointpur = 2
record.ecstat2 = 9
household_validator.validate_buyer_not_child(record)
expect(record.errors["ecstat2"]).to be_empty
end
end
end
end

Loading…
Cancel
Save