Browse Source

Update 2025 version of validation check

pull/2781/head
Manny Dinssa 9 months ago
parent
commit
57bd336ef9
  1. 12
      app/models/form/sales/pages/handover_date_check.rb
  2. 6
      app/models/validations/sales/soft_validations.rb
  3. 82
      spec/models/form/sales/pages/handover_date_check_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),

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

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

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

Loading…
Cancel
Save