Browse Source

Don't validate staircase mortgage for socialhomebuy

CLDC-3292-staircase-validation
Kat 10 months ago
parent
commit
a370223b5c
  1. 6
      app/models/validations/sales/sale_information_validations.rb
  2. 22
      spec/models/validations/sales/sale_information_validations_spec.rb

6
app/models/validations/sales/sale_information_validations.rb

@ -108,20 +108,20 @@ module Validations::Sales::SaleInformationValidations
def validate_non_staircasing_mortgage(record) def validate_non_staircasing_mortgage(record)
return unless record.value && record.deposit && record.equity 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? return unless record.saledate && record.form.start_year_after_2024?
if record.mortgage_used? if record.mortgage_used?
return unless record.mortgage return unless record.mortgage
if record.mortgage_and_deposit_total != record.expected_shared_ownership_deposit_value 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")) 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
end end
elsif record.mortgage_not_used? elsif record.mortgage_not_used?
if record.deposit != record.expected_shared_ownership_deposit_value 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")) 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
end end

22
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["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["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["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
end end
@ -758,6 +759,23 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to be_empty expect(record.errors["value"]).to be_empty
expect(record.errors["deposit"]).to be_empty expect(record.errors["deposit"]).to be_empty
expect(record.errors["equity"]).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 end
end end
@ -771,6 +789,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to be_empty expect(record.errors["value"]).to be_empty
expect(record.errors["deposit"]).to be_empty expect(record.errors["deposit"]).to be_empty
expect(record.errors["equity"]).to be_empty expect(record.errors["equity"]).to be_empty
expect(record.errors["type"]).to be_empty
end end
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["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["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["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
end end
@ -805,6 +825,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to be_empty expect(record.errors["value"]).to be_empty
expect(record.errors["deposit"]).to be_empty expect(record.errors["deposit"]).to be_empty
expect(record.errors["equity"]).to be_empty expect(record.errors["equity"]).to be_empty
expect(record.errors["type"]).to be_empty
end end
end end
end end
@ -818,6 +839,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
expect(record.errors["value"]).to be_empty expect(record.errors["value"]).to be_empty
expect(record.errors["deposit"]).to be_empty expect(record.errors["deposit"]).to be_empty
expect(record.errors["equity"]).to be_empty expect(record.errors["equity"]).to be_empty
expect(record.errors["type"]).to be_empty
end end
end end
end end

Loading…
Cancel
Save