Browse Source

Only run the hard validation for Social HomeBuy and RTA

pull/2209/head
Kat 2 years ago
parent
commit
6a18785fb3
  1. 2
      app/models/validations/sales/sale_information_validations.rb
  2. 3
      app/models/validations/sales/soft_validations.rb
  3. 28
      spec/models/validations/sales/sale_information_validations_spec.rb
  4. 22
      spec/models/validations/sales/soft_validations_spec.rb

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

@ -57,8 +57,8 @@ module Validations::Sales::SaleInformationValidations
end
def validate_grant_amount(record)
return unless record.grant
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")

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

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

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

@ -480,7 +480,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
context "when over the max" do
let(:record) { build(:sales_log, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) }
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)
@ -490,7 +490,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
context "when under the min" do
let(:record) { build(:sales_log, grant: 3, saledate: Time.zone.local(2024, 4, 5)) }
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)
@ -500,7 +500,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
context "when grant is blank" do
let(:record) { build(:sales_log, grant: nil, saledate: Time.zone.local(2024, 4, 5)) }
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)
@ -509,8 +509,28 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
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, grant: 3, saledate: Time.zone.local(2023, 4, 5)) }
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)

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

@ -660,6 +660,7 @@ 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
@ -667,6 +668,7 @@ RSpec.describe Validations::Sales::SoftValidations do
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
@ -674,13 +676,31 @@ RSpec.describe Validations::Sales::SoftValidations do
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" do
it "returns true for logs after 2024 with RTA" do
record.grant = 100_000
record.type = 8
record.saledate = Time.zone.local(2025, 1, 1)
expect(record).to be_grant_outside_common_range
end
it "returns true for logs after 2024 with socialBuy" do
record.grant = 100_000
record.type = 21
record.saledate = Time.zone.local(2025, 1, 1)
expect(record).to be_grant_outside_common_range
end
it "returns false 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).not_to be_grant_outside_common_range

Loading…
Cancel
Save