Browse Source

Benefits proportion validations

pull/304/head
baarkerlounger 3 years ago
parent
commit
f3179da6a9
  1. 40
      spec/models/case_log_spec.rb
  2. 41
      spec/models/validations/financial_validations_spec.rb

40
spec/models/case_log_spec.rb

@ -135,42 +135,6 @@ RSpec.describe CaseLog do
end end
end end
context "with tenant’s income from Universal Credit, state pensions or benefits" do
it "Cannot be All if person 1 works full time" do
expect {
described_class.create!(
benefits: "All",
ecstat1: "Full-time - 30 hours or more",
owning_organisation:,
managing_organisation:,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Cannot be All if person 1 works part time" do
expect {
described_class.create!(
benefits: "All",
ecstat1: "Part-time - Less than 30 hours",
owning_organisation:,
managing_organisation:,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "Cannot be 1 All if any of persons 2-4 are person 1's partner and work part or full time" do
expect {
described_class.create!(
benefits: "All",
relat2: "Partner",
ecstat2: "Part-time - Less than 30 hours",
owning_organisation:,
managing_organisation:,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "when saving income ranges" do context "when saving income ranges" do
it "validates net income maximum" do it "validates net income maximum" do
expect { expect {
@ -382,6 +346,10 @@ RSpec.describe CaseLog do
it "validates local authority" do it "validates local authority" do
expect(validator).to receive(:validate_la) expect(validator).to receive(:validate_la)
end end
it "validates benefits as proportion of income" do
expect(validator).to receive(:validate_net_income_uc_proportion)
end
end end
describe "status" do describe "status" do

41
spec/models/validations/financial_validations_spec.rb

@ -21,4 +21,45 @@ RSpec.describe Validations::FinancialValidations do
expect(record.errors["earnings"]).to include(match I18n.t("validations.financial.earnings.earnings_missing")) expect(record.errors["earnings"]).to include(match I18n.t("validations.financial.earnings.earnings_missing"))
end end
end end
describe "benefits proportion validations" do
context "when the proportion is all" do
it "validates that the lead tenant is not in full time employment" do
record.benefits = "All"
record.ecstat1 = "Full-time - 30 hours or more"
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to include(match I18n.t("validations.financial.benefits.part_or_full_time"))
end
it "validates that the lead tenant is not in part time employment" do
record.benefits = "All"
record.ecstat1 = "Part-time - Less than 30 hours"
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to include(match I18n.t("validations.financial.benefits.part_or_full_time"))
end
it "expects that the lead tenant is not in full-time or part-time employment" do
record.benefits = "All"
record.ecstat1 = "Retired"
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to be_empty
end
it "validates that the tenant's partner is not in full time employment" do
record.benefits = "All"
record.ecstat2 = "Part-time - Less than 30 hours"
record.relat2 = "Partner"
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to include(match I18n.t("validations.financial.benefits.part_or_full_time"))
end
it "expects that the tenant's partner is not in full-time or part-time employment" do
record.benefits = "All"
record.ecstat2 = "Retired"
record.relat2 = "Partner"
financial_validator.validate_net_income_uc_proportion(record)
expect(record.errors["benefits"]).to be_empty
end
end
end
end end

Loading…
Cancel
Save