Browse Source

CLDC-4313: Add maximum bounds to value and mortgage questions for 2026

CLDC-4313-resolve-unhandled-errors-on-large-numbers-in-numeric-fields
samyou-softwire 2 days ago
parent
commit
da1b0304e4
  1. 1
      app/models/form/sales/questions/mortgage_amount.rb
  2. 1
      app/models/form/sales/questions/purchase_price.rb
  3. 1
      app/models/form/sales/questions/value.rb
  4. 27
      spec/models/form/sales/questions/mortgage_amount_spec.rb
  5. 8
      spec/models/form/sales/questions/purchase_price_spec.rb
  6. 8
      spec/models/form/sales/questions/value_spec.rb

1
app/models/form/sales/questions/mortgage_amount.rb

@ -4,6 +4,7 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question
@id = "mortgage"
@type = "numeric"
@min = 1
@max = form.start_year_2026_or_later? ? 999_999 : nil
@step = 1
@width = 5
@prefix = "£"

1
app/models/form/sales/questions/purchase_price.rb

@ -4,6 +4,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question
@id = "value"
@type = "numeric"
@min = form.start_year_2026_or_later? ? 15_000 : 0
@max = form.start_year_2026_or_later? ? 999_999 : nil
@step = 0.01
@width = 5
@prefix = "£"

1
app/models/form/sales/questions/value.rb

@ -5,6 +5,7 @@ class Form::Sales::Questions::Value < ::Form::Question
@copy_key = form.start_year_2025_or_later? ? "sales.sale_information.value.#{page.id}" : "sales.sale_information.value"
@type = "numeric"
@min = form.start_year_2026_or_later? ? 15_000 : 0
@max = form.start_year_2026_or_later? ? 999_999 : nil
@step = 1
@width = 10
@prefix = "£"

27
spec/models/form/sales/questions/mortgage_amount_spec.rb

@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false))) }
let(:start_year_2026_or_later?) { false }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: start_year_2026_or_later?))) }
it "has correct page" do
expect(question.page).to be(page)
@ -50,4 +51,28 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do
expect(question).not_to be_derived(log)
end
end
context "with year 2025", metadata: { year: 25 } do
let(:start_year_2026_or_later?) { false }
it "has correct min" do
expect(question.min).to eq(1)
end
it "has correct max" do
expect(question.max).to be_nil
end
end
context "with year 2026", metadata: { year: 26 } do
let(:start_year_2026_or_later?) { true }
it "has correct min" do
expect(question.min).to eq(1)
end
it "has correct max" do
expect(question.max).to eq(999_999)
end
end
end

8
spec/models/form/sales/questions/purchase_price_spec.rb

@ -65,6 +65,10 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to be_nil
end
end
context "with year 2026", metadata: { year: 26 } do
@ -74,5 +78,9 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do
it "has correct min" do
expect(question.min).to eq(15_000)
end
it "has correct max" do
expect(question.max).to eq(999_999)
end
end
end

8
spec/models/form/sales/questions/value_spec.rb

@ -45,6 +45,10 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to be_nil
end
end
context "with year 2026", metadata: { year: 26 } do
@ -54,5 +58,9 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do
it "has correct min" do
expect(question.min).to eq(15_000)
end
it "has correct max" do
expect(question.max).to eq(999_999)
end
end
end

Loading…
Cancel
Save