Browse Source

CLDC-878 Validate basic monthly rent (#1228)

* Validate basic monthly rent

* Make the test description clearer
pull/1217/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
2787815a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/sales_log.rb
  2. 9
      app/models/validations/sales/sale_information_validations.rb
  3. 2
      config/locales/en.yml
  4. 57
      spec/models/validations/sales/sale_information_validations_spec.rb

4
app/models/sales_log.rb

@ -211,4 +211,8 @@ class SalesLog < Log
def old_persons_shared_ownership?
type == 24
end
def shared_owhership_scheme?
ownershipsch == 1
end
end

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

@ -54,4 +54,13 @@ module Validations::Sales::SaleInformationValidations
end
end
end
def validate_basic_monthly_rent(record)
return unless record.mrent && record.ownershipsch && record.type
if record.shared_owhership_scheme? && !record.old_persons_shared_ownership? && record.mrent > 9999
record.errors.add :mrent, I18n.t("validations.sale_information.monthly_rent.higher_than_expected")
record.errors.add :type, I18n.t("validations.sale_information.monthly_rent.higher_than_expected")
end
end
end

2
config/locales/en.yml

@ -426,6 +426,8 @@ en:
previous_property_type:
property_type_bedsit: "A bedsit can not have more than 1 bedroom"
discounted_ownership_value: "Mortgage, deposit, and grant total must equal £%{value_with_discount}"
monthly_rent:
higher_than_expected: "Basic monthly rent must be between £0 and £9,999"
soft_validations:
net_income:

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

@ -371,4 +371,61 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
end
end
end
describe "#validate_basic_monthly_rent" do
context "when within permitted bounds" do
let(:record) { build(:sales_log, mrent: 9998, ownershipsch: 1, type: 2) }
it "does not add an error" do
sale_information_validator.validate_basic_monthly_rent(record)
expect(record.errors[:mrent]).not_to be_present
expect(record.errors[:type]).not_to be_present
end
end
context "when the rent is blank" do
let(:record) { build(:sales_log, mrent: nil, ownershipsch: 1, type: 2) }
it "does not add an error" do
sale_information_validator.validate_basic_monthly_rent(record)
expect(record.errors[:mrent]).not_to be_present
expect(record.errors[:type]).not_to be_present
end
end
context "when the type is old persons shared ownership" do
let(:record) { build(:sales_log, mrent: 100_000, ownershipsch: 1, type: 24) }
it "does not add an error" do
sale_information_validator.validate_basic_monthly_rent(record)
expect(record.errors[:mrent]).not_to be_present
expect(record.errors[:type]).not_to be_present
end
end
context "when the type is blank" do
let(:record) { build(:sales_log, mrent: 100_000, ownershipsch: 1, type: nil) }
it "does not add an error" do
sale_information_validator.validate_basic_monthly_rent(record)
expect(record.errors[:mrent]).not_to be_present
expect(record.errors[:type]).not_to be_present
end
end
context "when higher than upper bound" do
let(:record) { build(:sales_log, mrent: 100_000, ownershipsch: 1, type: 2) }
it "adds an error" do
sale_information_validator.validate_basic_monthly_rent(record)
expect(record.errors[:mrent]).to include(I18n.t("validations.sale_information.monthly_rent.higher_than_expected"))
expect(record.errors[:type]).to include(I18n.t("validations.sale_information.monthly_rent.higher_than_expected"))
end
end
end
end

Loading…
Cancel
Save