Browse Source

CLDC-3178 Update grant validation type (#2209)

* Remove soft grant validation for 2024 onwards

* Validate grant amount for 24/25 onwards

* Only run the hard validation for Social HomeBuy and RTA

* Fix soft validation
pull/2224/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
5bcd677961
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      app/models/validations/sales/sale_information_validations.rb
  2. 3
      app/models/validations/sales/soft_validations.rb
  3. 2
      config/locales/en.yml
  4. 72
      spec/models/validations/sales/sale_information_validations_spec.rb
  5. 30
      spec/models/validations/sales/soft_validations_spec.rb

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

@ -55,4 +55,13 @@ module Validations::Sales::SaleInformationValidations
record.errors.add :type, I18n.t("validations.sale_information.monthly_rent.higher_than_expected")
end
end
def validate_grant_amount(record)
return unless record.saledate && record.form.start_year_after_2024?
return unless record.grant && (record.type == 8 || record.type == 21)
unless record.grant.between?(9_000, 16_000)
record.errors.add :grant, I18n.t("validations.sale_information.grant.out_of_range")
end
end
end

3
app/models/validations/sales/soft_validations.rb

@ -116,7 +116,8 @@ module Validations::Sales::SoftValidations
end
def grant_outside_common_range?
return unless grant
return unless grant && type && saledate
return if form.start_year_after_2024? && (type == 21 || type == 8)
!grant.between?(9_000, 16_000)
end

2
config/locales/en.yml

@ -615,6 +615,8 @@ en:
discounted_ownership_value: "The mortgage, deposit, and grant when added together is %{mortgage_deposit_and_grant_total}, and the purchase purchase price times by the discount is %{value_with_discount}. These figures should be the same"
monthly_rent:
higher_than_expected: "Basic monthly rent must be between £0.00 and £9,999.00"
grant:
out_of_range: "Loan, grants or subsidies must be between £9,000 and £16,000"
merge_request:
organisation_part_of_another_merge: "This organisation is part of another merge - select a different one"
organisation_not_selected: "Select an organisation from the search list"

72
spec/models/validations/sales/sale_information_validations_spec.rb

@ -467,4 +467,76 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
end
describe "#validate_grant_amount" do
context "when within permitted bounds" do
let(:record) { build(:sales_log, grant: 10_000, saledate: Time.zone.local(2024, 4, 5)) }
it "does not add an error" do
sale_information_validator.validate_grant_amount(record)
expect(record.errors).not_to be_present
end
end
context "when over the max" do
let(:record) { build(:sales_log, type: 8, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) }
it "adds an error" do
sale_information_validator.validate_grant_amount(record)
expect(record.errors[:grant]).to include("Loan, grants or subsidies must be between £9,000 and £16,000")
end
end
context "when under the min" do
let(:record) { build(:sales_log, type: 21, grant: 3, saledate: Time.zone.local(2024, 4, 5)) }
it "adds an error" do
sale_information_validator.validate_grant_amount(record)
expect(record.errors[:grant]).to include("Loan, grants or subsidies must be between £9,000 and £16,000")
end
end
context "when grant is blank" do
let(:record) { build(:sales_log, type: 21, grant: nil, saledate: Time.zone.local(2024, 4, 5)) }
it "does not add an error" do
sale_information_validator.validate_grant_amount(record)
expect(record.errors).not_to be_present
end
end
context "when over the max and type is not RTA of social homebuy" do
let(:record) { build(:sales_log, type: 9, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) }
it "does not add an error" do
sale_information_validator.validate_grant_amount(record)
expect(record.errors).not_to be_present
end
end
context "when under the min and type is not RTA of social homebuy" do
let(:record) { build(:sales_log, type: 9, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) }
it "does not add error" do
sale_information_validator.validate_grant_amount(record)
expect(record.errors).not_to be_present
end
end
context "with log before 2024/25 collection" do
let(:record) { build(:sales_log, type: 8, grant: 3, saledate: Time.zone.local(2023, 4, 5)) }
it "does not add an error" do
sale_information_validator.validate_grant_amount(record)
expect(record.errors).not_to be_present
end
end
end
end

30
spec/models/validations/sales/soft_validations_spec.rb

@ -660,21 +660,51 @@ RSpec.describe Validations::Sales::SoftValidations do
describe "#grant_outside_common_range?" do
it "returns true if grant is below 9000" do
record.grant = 1_000
record.type = 9
record.saledate = Time.zone.local(2024, 1, 1)
expect(record).to be_grant_outside_common_range
end
it "returns true if grant is above 16000" do
record.grant = 100_000
record.type = 9
record.saledate = Time.zone.local(2024, 1, 1)
expect(record).to be_grant_outside_common_range
end
it "returns false if grant is within expected range" do
record.grant = 10_000
record.type = 9
record.saledate = Time.zone.local(2024, 1, 1)
expect(record).not_to be_grant_outside_common_range
end
it "returns false for logs after 2024 with RTA" do
record.grant = 100_000
record.type = 8
record.saledate = Time.zone.local(2025, 1, 1)
expect(record).not_to be_grant_outside_common_range
end
it "returns false for logs after 2024 with socialBuy" do
record.grant = 100_000
record.type = 21
record.saledate = Time.zone.local(2025, 1, 1)
expect(record).not_to be_grant_outside_common_range
end
it "returns true for logs after 2024 with other type" do
record.grant = 100_000
record.type = 9
record.saledate = Time.zone.local(2025, 1, 1)
expect(record).to be_grant_outside_common_range
end
end
describe "#staircase_bought_above_fifty" do

Loading…
Cancel
Save