|
|
|
|
@ -311,12 +311,10 @@ RSpec.describe Validations::Sales::FinancialValidations do
|
|
|
|
|
|
|
|
|
|
context "when buyer 2 is not a child" do |
|
|
|
|
before do |
|
|
|
|
record.update!(ecstat2: rand(0..8)) |
|
|
|
|
record.reload |
|
|
|
|
record.ecstat2 = rand(0..8) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add an error if buyer 2 has an income" do |
|
|
|
|
record.ecstat2 = rand(0..8) |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_child_income(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
@ -324,29 +322,31 @@ RSpec.describe Validations::Sales::FinancialValidations do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when buyer 2 is a child" do |
|
|
|
|
it "does not add an error if buyer 2 has no income" do |
|
|
|
|
record.saledate = Time.zone.local(2023, 4, 3) |
|
|
|
|
record.ecstat2 = 9 |
|
|
|
|
record.income2 = 0 |
|
|
|
|
financial_validator.validate_child_income(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds errors if buyer 2 has an income" do |
|
|
|
|
record.saledate = Time.zone.local(2023, 4, 3) |
|
|
|
|
record.ecstat2 = 9 |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_child_income(record) |
|
|
|
|
expect(record.errors["ecstat2"]).to include(match I18n.t("validations.financial.income.child_has_income")) |
|
|
|
|
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.child_has_income")) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add an error if the saledate is before the 23/24 collection window" do |
|
|
|
|
record.saledate = Time.zone.local(2022, 4, 3) |
|
|
|
|
record.ecstat2 = 9 |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_child_income(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
context "and saledate is current" do |
|
|
|
|
let(:record) { build(:sales_log, :saledate_today, ecstat2: 9) } |
|
|
|
|
|
|
|
|
|
it "does not add an error if buyer 2 has no income" do |
|
|
|
|
record.income2 = 0 |
|
|
|
|
financial_validator.validate_child_income(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds errors if buyer 2 has an income" do |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_child_income(record) |
|
|
|
|
expect(record.errors["ecstat2"]).to include(match I18n.t("validations.financial.income.child_has_income")) |
|
|
|
|
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.child_has_income")) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and saledate is before the 23/24 collection window" do |
|
|
|
|
let(:record) { build(:sales_log, saledate: Time.zone.local(2022, 4, 3), ecstat2: 9) } |
|
|
|
|
|
|
|
|
|
it "does not add an error if the saledate is before the 23/24 collection window" do |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_child_income(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|