From 3d84065fac434c1ff1efcb05b7cf6f02d76b9211 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 14 Mar 2024 14:00:50 +0000 Subject: [PATCH] Add errors to type --- .../sales/sale_information_validations.rb | 20 ++++++++-------- .../sale_information_validations_spec.rb | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 266aa1a9f..fb8a76216 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/app/models/validations/sales/sale_information_validations.rb @@ -109,7 +109,7 @@ module Validations::Sales::SaleInformationValidations def validate_non_staircasing_mortgage(record) return unless record.saledate && record.form.start_year_after_2024? return unless record.value && record.deposit && record.equity - return unless record.ownershipsch == 1 && record.type && record.mortgageused && record.is_not_staircasing? + return unless record.shared_ownership_scheme? && record.type && record.mortgageused && record.is_not_staircasing? if record.social_homebuy? add_non_staircasing_socialhomebuy_mortgage_errors(record) @@ -121,7 +121,7 @@ module Validations::Sales::SaleInformationValidations def validate_staircasing_mortgage(record) return unless record.saledate && record.form.start_year_after_2024? return unless record.value && record.deposit && record.stairbought - return unless record.is_staircase? && record.ownershipsch == 1 && record.type && record.mortgageused + return unless record.shared_ownership_scheme? && record.type && record.mortgageused && record.is_staircase? if record.social_homebuy? add_staircasing_socialhomebuy_mortgage_errors(record) @@ -146,13 +146,13 @@ module Validations::Sales::SaleInformationValidations return unless record.mortgage if record.mortgage_deposit_and_discount_total != record.expected_shared_ownership_deposit_value - %i[mortgage value deposit cashdis equity].each do |field| + %i[mortgage value deposit cashdis equity type].each do |field| record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_used_socialhomebuy", mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_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_and_discount_total != record.expected_shared_ownership_deposit_value - %i[mortgageused value deposit cashdis equity].each do |field| + %i[mortgageused value deposit cashdis equity type].each do |field| record.errors.add field, I18n.t("validations.sale_information.non_staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit_and_discount_total: record.field_formatted_as_currency("deposit_and_discount_total"), expected_shared_ownership_deposit_value: record.field_formatted_as_currency("expected_shared_ownership_deposit_value")) end end @@ -164,13 +164,13 @@ module Validations::Sales::SaleInformationValidations 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 @@ -184,12 +184,12 @@ module Validations::Sales::SaleInformationValidations return unless record.mortgage if record.mortgage_deposit_and_discount_total != record.stairbought_part_of_value - %i[mortgage value deposit cashdis stairbought].each do |field| + %i[mortgage value deposit cashdis stairbought type].each do |field| record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) end end elsif record.deposit_and_discount_total != record.stairbought_part_of_value - %i[mortgageused value deposit cashdis stairbought].each do |field| + %i[mortgageused value deposit cashdis stairbought type].each do |field| record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit_and_discount_total: record.field_formatted_as_currency("deposit_and_discount_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) end end @@ -200,12 +200,12 @@ module Validations::Sales::SaleInformationValidations return unless record.mortgage if record.mortgage_and_deposit_total != record.stairbought_part_of_value - %i[mortgage value deposit stairbought].each do |field| + %i[mortgage value deposit stairbought type].each do |field| record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_used", mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_value")) end end elsif record.deposit != record.stairbought_part_of_value - %i[mortgageused value deposit stairbought].each do |field| + %i[mortgageused value deposit stairbought type].each do |field| record.errors.add field, I18n.t("validations.sale_information.staircasing_mortgage.mortgage_not_used", deposit: record.field_formatted_as_currency("deposit"), stairbought_part_of_value: record.field_formatted_as_currency("stairbought_part_of_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 6091c47c4..5fde5dfb3 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.") expect(record.errors["cashdis"]).not_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 @@ -760,6 +761,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to include("The mortgage, deposit and cash discount added together is £15,200.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, deposit and cash discount added together is £15,200.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.") expect(record.errors["cashdis"]).to include("The mortgage, deposit and cash discount added together is £15,200.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, deposit and cash discount added together is £15,200.00 and the purchase price times by the equity is £8,400.00. These figures should be the same.") end end @@ -775,6 +777,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -791,6 +794,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -805,6 +809,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end @@ -825,6 +830,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.") expect(record.errors["cashdis"]).not_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 @@ -841,6 +847,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to include("The deposit and cash discount added together is £5,200.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 and cash discount added together is £5,200.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["cashdis"]).to include("The deposit and cash discount added together is £5,200.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 and cash discount added together is £5,200.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 @@ -856,6 +863,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -872,6 +880,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -886,6 +895,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -902,6 +912,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["equity"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -933,6 +944,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 percentage bought times the purchase price 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 percentage bought times the purchase price is £8,400.00. These figures should be the same.") expect(record.errors["stairbought"]).to include("The mortgage and deposit added together is £15,000.00 and the percentage bought times the purchase price 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 percentage bought times the purchase price is £8,400.00. These figures should be the same.") expect(record.errors["cashdis"]).not_to include("The mortgage and deposit added together is £15,000.00 and the percentage bought times the purchase price is £8,400.00. These figures should be the same.") end @@ -949,6 +961,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to include("The mortgage, deposit and cash discount added together is £15,200.00 and the percentage bought times the purchase price is £8,400.00. These figures should be the same.") expect(record.errors["stairbought"]).to include("The mortgage, deposit and cash discount added together is £15,200.00 and the percentage bought times the purchase price is £8,400.00. These figures should be the same.") expect(record.errors["cashdis"]).to include("The mortgage, deposit and cash discount added together is £15,200.00 and the percentage bought times the purchase price is £8,400.00. These figures should be the same.") + expect(record.errors["type"]).to include("The mortgage, deposit and cash discount added together is £15,200.00 and the percentage bought times the purchase price is £8,400.00. These figures should be the same.") end end @@ -964,6 +977,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["stairbought"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -980,6 +994,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["stairbought"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -994,6 +1009,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["stairbought"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -1009,6 +1025,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["stairbought"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end @@ -1032,6 +1049,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["value"]).to include("The deposit is £5,000.00 and the percentage bought times the purchase price 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 percentage bought times the purchase price is £8,400.00. As no mortgage was used, these figures should be the same.") expect(record.errors["stairbought"]).to include("The deposit is £5,000.00 and the percentage bought times the purchase price 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 percentage bought times the purchase price is £8,400.00. As no mortgage was used, these figures should be the same.") expect(record.errors["cashdis"]).not_to include("The deposit is £5,000.00 and the percentage bought times the purchase price is £8,400.00. As no mortgage was used, these figures should be the same.") end @@ -1048,6 +1066,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to include("The deposit and cash discount added together is £5,200.00 and the percentage bought times the purchase price is £8,400.00. As no mortgage was used, these figures should be the same.") expect(record.errors["stairbought"]).to include("The deposit and cash discount added together is £5,200.00 and the percentage bought times the purchase price is £8,400.00. As no mortgage was used, these figures should be the same.") expect(record.errors["cashdis"]).to include("The deposit and cash discount added together is £5,200.00 and the percentage bought times the purchase price is £8,400.00. As no mortgage was used, these figures should be the same.") + expect(record.errors["type"]).to include("The deposit and cash discount added together is £5,200.00 and the percentage bought times the purchase price is £8,400.00. As no mortgage was used, these figures should be the same.") end end @@ -1063,6 +1082,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["stairbought"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -1079,6 +1099,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["stairbought"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -1093,6 +1114,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["stairbought"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end @@ -1108,6 +1130,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["deposit"]).to be_empty expect(record.errors["stairbought"]).to be_empty expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end end