Browse Source

Validate grant amount for 24/25 onwards

pull/2209/head
Kat 2 years ago
parent
commit
b361b2fdc0
  1. 9
      app/models/validations/sales/sale_information_validations.rb
  2. 2
      config/locales/en.yml
  3. 52
      spec/models/validations/sales/sale_information_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.grant
return unless record.saledate && record.form.start_year_after_2024?
unless record.grant.between?(9_000, 16_000)
record.errors.add :grant, I18n.t("validations.sale_information.grant.out_of_range")
end
end
end

2
config/locales/en.yml

@ -613,6 +613,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"

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

@ -467,4 +467,56 @@ 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, 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, 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, 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 "with log before 2024/25 collection" do
let(:record) { build(:sales_log, 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

Loading…
Cancel
Save