From a370223b5cd20a59243720df6e5c22d5d89b6aed Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 12 Mar 2024 08:18:29 +0000 Subject: [PATCH] Don't validate staircase mortgage for socialhomebuy --- .../sales/sale_information_validations.rb | 6 ++--- .../sale_information_validations_spec.rb | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 66ca8b1a0..9fd9e6be6 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -108,20 +108,20 @@ module Validations::Sales::SaleInformationValidations def validate_non_staircasing_mortgage(record) return unless record.value && record.deposit && record.equity - return unless record.is_not_staircasing? + return unless record.is_not_staircasing? && record.type != 18 return unless record.saledate && record.form.start_year_after_2024? if record.mortgage_used? return unless record.mortgage if record.mortgage_and_deposit_total != record.expected_shared_ownership_deposit_value - %i[mortgage value deposit equity].each do |field| + %i[mortgage value deposit equity type].each do |field| record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) end end elsif record.mortgage_not_used? if record.deposit != record.expected_shared_ownership_deposit_value - %i[mortgageused value deposit equity].each do |field| + %i[mortgageused value deposit equity type].each do |field| record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_not_used", deposit: record.field_formatted_as_currency("deposit"), expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) end end diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index 9ae84834c..7130fa74b 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -744,6 +744,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["value"]).to include("The mortgage and deposit added together is £15,000.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.") expect(record.errors["deposit"]).to include("The mortgage and deposit added together is £15,000.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.") expect(record.errors["equity"]).to include("The mortgage and deposit added together is £15,000.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.") + expect(record.errors["type"]).to include("The mortgage and deposit added together is £15,000.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.") end end @@ -758,6 +759,23 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["value"]).to be_empty expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty + expect(record.errors["type"]).to be_empty + end + end + + context "and it is not a staircase transaction with social homebuy" do + before do + record.staircase = 2 + record.type = 18 + end + + it "does not add an error" do + sale_information_validator.validate_non_staircasing_mortgage(record) + expect(record.errors["mortgage"]).to be_empty + expect(record.errors["value"]).to be_empty + expect(record.errors["deposit"]).to be_empty + expect(record.errors["equity"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -771,6 +789,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["value"]).to be_empty expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty + expect(record.errors["type"]).to be_empty end end @@ -791,6 +810,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["value"]).to include("The deposit is £5,000.00 and the purchase price times by the equity is £8,400.00. As no mortgage was used, these figures should be the same.") expect(record.errors["deposit"]).to include("The deposit is £5,000.00 and the purchase price times by the equity is £8,400.00. As no mortgage was used, these figures should be the same.") expect(record.errors["equity"]).to include("The deposit is £5,000.00 and the purchase price times by the equity is £8,400.00. As no mortgage was used, these figures should be the same.") + expect(record.errors["type"]).to include("The deposit is £5,000.00 and the purchase price times by the equity is £8,400.00. As no mortgage was used, these figures should be the same.") end end @@ -805,6 +825,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["value"]).to be_empty expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -818,6 +839,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["value"]).to be_empty expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty + expect(record.errors["type"]).to be_empty end end end