diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index 19c2a13ec..6712a45a2 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -37,6 +37,12 @@ module Validations::Sales::SoftValidations deposit > savings * 4 / 3 end + def shared_ownership_deposit_invalid? + return unless mortgage && deposit && cashdis && value && equity + + mortgage + deposit + cashdis != value * equity / 100 + end + def hodate_3_years_or_more_saledate? return unless hodate && saledate diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index 34f49d847..d0a8b5244 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/spec/models/validations/sales/soft_validations_spec.rb @@ -254,6 +254,85 @@ RSpec.describe Validations::Sales::SoftValidations do .not_to be_deposit_over_soft_max end end + + context "when validating shared ownership deposit" do + it "returns false if MORTGAGE + DEPOSIT + CASHDIS are equal VALUE * EQUITY/100" do + record.mortgage = 1000 + record.deposit = 1000 + record.cashdis = 1000 + record.value = 3000 + record.equity = 100 + + expect(record) + .not_to be_shared_ownership_deposit_invalid + end + + it "returns false if no mortgage is given" do + record.mortgage = nil + record.deposit = 1000 + record.cashdis = 1000 + record.value = 3000 + record.equity = 100 + + expect(record) + .not_to be_shared_ownership_deposit_invalid + end + + it "returns false if no deposit is given" do + record.mortgage = 1000 + record.deposit = nil + record.cashdis = 1000 + record.value = 3000 + record.equity = 100 + + expect(record) + .not_to be_shared_ownership_deposit_invalid + end + + it "returns false if no cashdis is given" do + record.mortgage = 1000 + record.deposit = 1000 + record.cashdis = nil + record.value = 3000 + record.equity = 100 + + expect(record) + .not_to be_shared_ownership_deposit_invalid + end + + it "returns false if no value is given" do + record.mortgage = 1000 + record.deposit = 1000 + record.cashdis = 1000 + record.value = nil + record.equity = 100 + + expect(record) + .not_to be_shared_ownership_deposit_invalid + end + + it "returns false if no equity is given" do + record.mortgage = 1000 + record.deposit = 1000 + record.cashdis = 1000 + record.value = 3000 + record.equity = nil + + expect(record) + .not_to be_shared_ownership_deposit_invalid + end + + it "returns true if MORTGAGE + DEPOSIT + CASHDIS are not equal VALUE * EQUITY/100" do + record.mortgage = 1000 + record.deposit = 1000 + record.cashdis = 1000 + record.value = 4323 + record.equity = 100 + + expect(record) + .to be_shared_ownership_deposit_invalid + end + end end describe "hodate_more_than_3_years_before_saledate" do