|
|
|
|
@ -5,109 +5,146 @@ RSpec.describe Validations::Sales::FinancialValidations do
|
|
|
|
|
|
|
|
|
|
let(:validator_class) { Class.new { include Validations::Sales::FinancialValidations } } |
|
|
|
|
|
|
|
|
|
describe "income validations" do |
|
|
|
|
let(:record) { FactoryBot.create(:sales_log, ownershipsch: 1, la: "E08000035") } |
|
|
|
|
describe "income validations for shared ownership" do |
|
|
|
|
let(:record) { FactoryBot.create(:sales_log, ownershipsch: 1) } |
|
|
|
|
|
|
|
|
|
context "with shared ownership" do |
|
|
|
|
context "and non london borough" do |
|
|
|
|
(0..8).each do |ecstat| |
|
|
|
|
it "adds an error when buyer 1 income is over hard max for ecstat #{ecstat}" do |
|
|
|
|
context "in a non london borough" do |
|
|
|
|
before do |
|
|
|
|
record.update!(la: "E08000035") |
|
|
|
|
record.reload |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds errors if buyer 1's economic status is not child and has income over 80,000" do |
|
|
|
|
record.income1 = 85_000 |
|
|
|
|
record.ecstat1 = ecstat |
|
|
|
|
record.ecstat1 = rand(0..8) |
|
|
|
|
financial_validator.validate_income1(record) |
|
|
|
|
expect(record.errors["income1"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["income1"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["ecstat1"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["ownershipsch"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["la"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["postcode_full"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds an error when buyer 2 income is over hard max for ecstat #{ecstat}" do |
|
|
|
|
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["ecstat1"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds errors if buyer 2's economic status is not child and has income over 80,000" do |
|
|
|
|
record.income2 = 85_000 |
|
|
|
|
record.ecstat2 = ecstat |
|
|
|
|
record.ecstat2 = rand(0..8) |
|
|
|
|
financial_validator.validate_income2(record) |
|
|
|
|
expect(record.errors["income2"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["ecstat2"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 80_000)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add errors if buyer 1 has not set economic status" do |
|
|
|
|
record.income1 = 85_000 |
|
|
|
|
financial_validator.validate_income1(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "validates that the income is within the expected range for the tenant’s employment status" do |
|
|
|
|
it "does not add errors if buyer 1 has income below 80_000" do |
|
|
|
|
record.income1 = 75_000 |
|
|
|
|
record.ecstat1 = 1 |
|
|
|
|
record.ecstat1 = rand(0..8) |
|
|
|
|
financial_validator.validate_income1(record) |
|
|
|
|
expect(record.errors["income1"]).to be_empty |
|
|
|
|
expect(record.errors["ecstat1"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["la"]).to be_empty |
|
|
|
|
expect(record.errors["postcode_full"]).to be_empty |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add errors if buyer 2 has not set economic status" do |
|
|
|
|
record.income2 = 85_000 |
|
|
|
|
financial_validator.validate_income2(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add errors if buyer 2 has income below 80_000" do |
|
|
|
|
record.income2 = 75_000 |
|
|
|
|
record.ecstat2 = rand(0..8) |
|
|
|
|
financial_validator.validate_income2(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds an error when combined income is over the limit" do |
|
|
|
|
it "adds errors when combined income is over 80_000" do |
|
|
|
|
record.income1 = 45_000 |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_income1(record) |
|
|
|
|
financial_validator.validate_income2(record) |
|
|
|
|
expect(record.errors["income1"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["income2"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 80_000)) |
|
|
|
|
financial_validator.validate_combined_income(record) |
|
|
|
|
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 80_000)) |
|
|
|
|
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 80_000)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add errors when combined income is under 80_000" do |
|
|
|
|
record.income1 = 35_000 |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_combined_income(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and a london borough" do |
|
|
|
|
context "in a london borough" do |
|
|
|
|
before do |
|
|
|
|
record.update!(la: "E09000030") |
|
|
|
|
record.reload |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
(0..8).each do |ecstat| |
|
|
|
|
it "adds an error when buyer 1 income is over hard max for ecstat #{ecstat}" do |
|
|
|
|
it "adds errors if buyer 1's economic status is not child and has income over 90,000" do |
|
|
|
|
record.income1 = 95_000 |
|
|
|
|
record.ecstat1 = ecstat |
|
|
|
|
record.ecstat1 = rand(0..8) |
|
|
|
|
financial_validator.validate_income1(record) |
|
|
|
|
expect(record.errors["income1"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["income1"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["ecstat1"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["ownershipsch"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["la"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["postcode_full"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "validates that the income is within the expected range for the tenant’s employment status" do |
|
|
|
|
record.income1 = 85_000 |
|
|
|
|
record.ecstat1 = 1 |
|
|
|
|
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["ecstat1"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds errors if buyer 2's economic status is not child and has income over 90,000" do |
|
|
|
|
record.income2 = 95_000 |
|
|
|
|
record.ecstat2 = rand(0..8) |
|
|
|
|
financial_validator.validate_income2(record) |
|
|
|
|
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["ecstat2"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["la"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.financial.income.over_hard_max", hard_max: 90_000)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add errors if buyer 1 has not set economic status" do |
|
|
|
|
record.income1 = 95_000 |
|
|
|
|
financial_validator.validate_income1(record) |
|
|
|
|
expect(record.errors["income1"]).to be_empty |
|
|
|
|
expect(record.errors["ecstat1"]).to be_empty |
|
|
|
|
expect(record.errors["ownershipsch"]).to be_empty |
|
|
|
|
expect(record.errors["la"]).to be_empty |
|
|
|
|
expect(record.errors["postcode_full"]).to be_empty |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds an error when combined income is over the limit" do |
|
|
|
|
record.income1 = 50_000 |
|
|
|
|
record.income2 = 45_000 |
|
|
|
|
it "does not add errors if buyer 1 has income below 90_000" do |
|
|
|
|
record.income1 = 75_000 |
|
|
|
|
record.ecstat1 = rand(0..8) |
|
|
|
|
financial_validator.validate_income1(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add errors if buyer 2 has not set economic status" do |
|
|
|
|
record.income2 = 95_000 |
|
|
|
|
financial_validator.validate_income2(record) |
|
|
|
|
expect(record.errors["income1"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["income2"]) |
|
|
|
|
.to include(match I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add errors if buyer 2 has income below 90_000" do |
|
|
|
|
record.income2 = 75_000 |
|
|
|
|
record.ecstat2 = rand(0..8) |
|
|
|
|
financial_validator.validate_income2(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "adds errors when combined income is over 90_000" do |
|
|
|
|
record.income1 = 55_000 |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_combined_income(record) |
|
|
|
|
expect(record.errors["income1"]).to include(match I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 90_000)) |
|
|
|
|
expect(record.errors["income2"]).to include(match I18n.t("validations.financial.income.combined_over_hard_max", hard_max: 90_000)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "does not add errors when combined income is under 90_000" do |
|
|
|
|
record.income1 = 35_000 |
|
|
|
|
record.income2 = 40_000 |
|
|
|
|
financial_validator.validate_combined_income(record) |
|
|
|
|
expect(record.errors).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|