Browse Source

CLDC-3757: Sales - Change values in validation check for Q84 (25/26) (#2781)

* Update 2025 version of validation check

* Update validation for 2025

* Put two if statements into one

* Different approach to comparing dates

* Alternative method to compare dates

* Update tests
pull/2800/head
Manny Dinssa 2 months ago committed by GitHub
parent
commit
bc1fe83750
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      app/models/form/sales/pages/handover_date_check.rb
  2. 5
      app/models/validations/sales/sale_information_validations.rb
  3. 6
      app/models/validations/sales/soft_validations.rb
  4. 2
      config/locales/validations/sales/sale_information.en.yml
  5. 82
      spec/models/form/sales/pages/handover_date_check_spec.rb
  6. 5
      spec/models/validations/sales/sale_information_validations_spec.rb

12
app/models/form/sales/pages/handover_date_check.rb

@ -3,8 +3,6 @@ class Form::Sales::Pages::HandoverDateCheck < ::Form::Page
super
@id = "handover_date_check"
@copy_key = "sales.soft_validations.hodate_check"
@depends_on = [{ "saledate_check" => nil, "hodate_3_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_3_years_or_more_saledate?" => true }]
@informative_text = {}
@title_text = {
"translation" => "forms.#{form.start_date.year}.#{@copy_key}.title_text",
@ -12,6 +10,16 @@ class Form::Sales::Pages::HandoverDateCheck < ::Form::Page
}
end
def depends_on
if form.start_year_2025_or_later?
[{ "saledate_check" => nil, "hodate_5_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_5_years_or_more_saledate?" => true }]
else
[{ "saledate_check" => nil, "hodate_3_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_3_years_or_more_saledate?" => true }]
end
end
def questions
@questions ||= [
Form::Sales::Questions::HandoverDateCheck.new(nil, nil, self),

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

@ -12,7 +12,10 @@ module Validations::Sales::SaleInformationValidations
record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.must_be_after_hodate")
end
if record.saledate - record.hodate >= 3.years && record.form.start_year_2024_or_later?
if (record.saledate - 5.years) >= record.hodate && record.form.start_year_2025_or_later?
record.errors.add :hodate, I18n.t("validations.sales.sale_information.hodate.must_be_less_than_5_years_from_saledate")
record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.must_be_less_than_5_years_from_hodate")
elsif (record.saledate - 3.years) >= record.hodate && record.startdate.year <= 2024
record.errors.add :hodate, I18n.t("validations.sales.sale_information.hodate.must_be_less_than_3_years_from_saledate")
record.errors.add :saledate, I18n.t("validations.sales.sale_information.saledate.must_be_less_than_3_years_from_hodate")
end

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

@ -110,6 +110,12 @@ module Validations::Sales::SoftValidations
saledate - hodate >= 3.years
end
def hodate_5_years_or_more_saledate?
return unless hodate && saledate
saledate - hodate >= 5.years
end
def purchase_price_higher_or_lower_text
value < sale_range.soft_min ? "lower" : "higher"
end

2
config/locales/validations/sales/sale_information.en.yml

@ -8,9 +8,11 @@ en:
hodate:
must_be_before_saledate: "Practical completion or handover date must be before sale completion date."
must_be_less_than_3_years_from_saledate: "Practical completion or handover date must be less than 3 years before sale completion date."
must_be_less_than_5_years_from_saledate: "Practical completion or handover date must be less than 5 years before sale completion date."
saledate:
must_be_after_hodate: "Sale completion date must be after practical completion or handover date."
must_be_less_than_3_years_from_hodate: "Sale completion date must be less than 3 years after practical completion or handover date."
must_be_less_than_5_years_from_hodate: "Sale completion date must be less than 5 years after practical completion or handover date."
must_be_after_exdate: "Sale completion date must be after contract exchange date."
must_be_less_than_1_year_from_exdate: "Sale completion date must be less than 1 year after contract exchange date."
mortgage_used_year: "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for the selected year."

82
spec/models/form/sales/pages/handover_date_check_spec.rb

@ -5,44 +5,66 @@ RSpec.describe Form::Sales::Pages::HandoverDateCheck, type: :model do
let(:page_id) { "" }
let(:page_definition) { nil }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
let(:subsection) { instance_double(Form::Subsection, form:) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
context "when form start year is <= 2024" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: false) }
let(:subsection) { instance_double(Form::Subsection, form:) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[hodate_check])
end
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has the correct id" do
expect(page.id).to eq("handover_date_check")
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[hodate_check])
end
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "forms.2024.sales.soft_validations.hodate_check.title_text",
"arguments" => [],
})
end
it "has the correct id" do
expect(page.id).to eq("handover_date_check")
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({})
end
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "forms.2024.sales.soft_validations.hodate_check.title_text",
"arguments" => [],
})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "hodate_3_years_or_more_saledate?" => true, "saledate_check" => nil },
{ "hodate_3_years_or_more_saledate?" => true, "saledate_check" => 1 },
])
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "hodate_3_years_or_more_saledate?" => true, "saledate_check" => nil },
{ "hodate_3_years_or_more_saledate?" => true, "saledate_check" => 1 },
])
end
it "is interruption screen page" do
expect(page.interruption_screen?).to eq(true)
end
it "is interruption screen page" do
expect(page.interruption_screen?).to eq(true)
it "is has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[hodate saledate])
end
end
it "is has correct interruption_screen_question_ids" do
expect(page.interruption_screen_question_ids).to eq(%w[hodate saledate])
context "when form start year is 2025" do
let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1), start_year_2025_or_later?: true) }
let(:subsection) { instance_double(Form::Subsection, form:) }
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "forms.2025.sales.soft_validations.hodate_check.title_text",
"arguments" => [],
})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "hodate_5_years_or_more_saledate?" => true, "saledate_check" => nil },
{ "hodate_5_years_or_more_saledate?" => true, "saledate_check" => 1 },
])
end
end
end

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

@ -60,10 +60,11 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
context "and form year is 2023 or earlier" do
let(:record) { build(:sales_log, hodate: Date.new(2020, 12, 1), saledate: Date.new(2023, 12, 1)) }
it "does not add an error" do
it "does add an error" do
sale_information_validator.validate_practical_completion_date(record)
expect(record.errors).not_to be_present
expect(record.errors[:hodate]).to be_present
expect(record.errors[:saledate]).to be_present
end
end

Loading…
Cancel
Save