Browse Source

CLDC-3183 Validate previous tenure for discounted sales (#2206)

* Validate previous tenure for discounted sales

* typo
pull/2213/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
44abe22ea9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      app/models/validations/sales/household_validations.rb
  2. 1
      config/locales/en.yml
  3. 75
      spec/models/validations/sales/household_validations_spec.rb

10
app/models/validations/sales/household_validations.rb

@ -30,6 +30,16 @@ module Validations::Sales::HouseholdValidations
end end
end end
def validate_buyer1_previous_tenure(record)
return unless record.saledate && record.form.start_year_after_2024?
return unless record.discounted_ownership_sale? && record.prevten
if [3, 4, 5, 6, 7, 9, 0].include?(record.prevten)
record.errors.add :prevten, I18n.t("validations.household.prevten.invalid_for_discounted_sale")
record.errors.add :ownershipsch, I18n.t("validations.household.prevten.invalid_for_discounted_sale")
end
end
private private
def validate_person_age_matches_relationship(record, person_num) def validate_person_age_matches_relationship(record, person_num)

1
config/locales/en.yml

@ -503,6 +503,7 @@ en:
internal_transfer: "Answer cannot be %{prevten} as this tenancy is an internal transfer" internal_transfer: "Answer cannot be %{prevten} as this tenancy is an internal transfer"
la_general_needs: la_general_needs:
internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as it’s an internal transfer and a private registered provider is on the tenancy agreement" internal_transfer: "Answer cannot be a fixed-term or lifetime local authority general needs tenancy as it’s an internal transfer and a private registered provider is on the tenancy agreement"
invalid_for_discounted_sale: "Buyer 1’s previous tenure should be “local authority tenant” or “private registered provider or housing association tenant” for discounted sales"
referral: referral:
secure_tenancy: "Answer must be internal transfer as this is a secure tenancy" secure_tenancy: "Answer must be internal transfer as this is a secure tenancy"
rsnvac_non_temp: "Answer cannot be this source of referral as this is a re-let to tenant who occupied the same property as temporary accommodation" rsnvac_non_temp: "Answer cannot be this source of referral as this is a re-let to tenant who occupied the same property as temporary accommodation"

75
spec/models/validations/sales/household_validations_spec.rb

@ -268,4 +268,79 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
end end
end end
describe "#validate_buyer1_previous_tenure" do
let(:record) { build(:sales_log) }
let(:now) { Time.zone.local(2024, 4, 4) }
before do
Timecop.freeze(now)
Singleton.__init__(FormHandler)
record.ownershipsch = 2
record.saledate = now
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
it "adds an error when previous tenure is not valid" do
[3, 4, 5, 6, 7, 9, 0].each do |prevten|
record.prevten = prevten
household_validator.validate_buyer1_previous_tenure(record)
expect(record.errors["prevten"]).to include("Buyer 1’s previous tenure should be “local authority tenant” or “private registered provider or housing association tenant” for discounted sales")
expect(record.errors["ownershipsch"]).to include("Buyer 1’s previous tenure should be “local authority tenant” or “private registered provider or housing association tenant” for discounted sales")
end
end
it "does not add an error when previous tenure is allowed" do
[1, 2].each do |prevten|
record.prevten = prevten
household_validator.validate_buyer1_previous_tenure(record)
expect(record.errors).to be_empty
end
end
it "does not add an error if previous tenure is not given" do
record.prevten = nil
household_validator.validate_buyer1_previous_tenure(record)
expect(record.errors).to be_empty
end
it "does not add an error for shared ownership sale" do
record.ownershipsch = 1
[1, 2, 3, 4, 5, 6, 7, 9, 0].each do |prevten|
record.prevten = prevten
household_validator.validate_buyer1_previous_tenure(record)
expect(record.errors).to be_empty
end
end
it "does not add an error for outright sale" do
record.ownershipsch = 3
[1, 2, 3, 4, 5, 6, 7, 9, 0].each do |prevten|
record.prevten = prevten
household_validator.validate_buyer1_previous_tenure(record)
expect(record.errors).to be_empty
end
end
context "with 23/24 logs" do
let(:now) { Time.zone.local(2023, 4, 4) }
it "does not add an error for outright sale" do
record.ownershipsch = 2
[1, 2, 3, 4, 5, 6, 7, 9, 0].each do |prevten|
record.prevten = prevten
household_validator.validate_buyer1_previous_tenure(record)
expect(record.errors).to be_empty
end
end
end
end
end end

Loading…
Cancel
Save