diff --git a/spec/models/form/sales/pages/person_known_spec.rb b/spec/models/form/sales/pages/person_known_spec.rb index 141473138..910a7e148 100644 --- a/spec/models/form/sales/pages/person_known_spec.rb +++ b/spec/models/form/sales/pages/person_known_spec.rb @@ -3,11 +3,13 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } - context "without joint purchase" do - let(:page_id) { "person_2_known" } - let(:page_definition) { nil } - let(:subsection) { instance_double(Form::Subsection) } - let(:person_index) { 2 } + let(:page_id) { "person_2_known" } + let(:page_definition) { nil } + let(:person_index) { 2 } + + context "with 2024 form" do + let(:form) { Form.new(nil, 2024, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:) } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -153,4 +155,96 @@ RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do end end end + + context "with 2026 form" do + let(:form) { Form.new(nil, 2026, [], "sales") } + let(:subsection) { instance_double(Form::Subsection, form:) } + + context "with person 2" do + let(:page_id) { "person_2_known" } + let(:person_index) { 2 } + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ + "not_joint_purchase?" => true, + "hholdcount" => { + "operator" => ">=", + "operand" => 2, + }, + }]) + end + end + + context "with person 3" do + let(:page_id) { "person_3_known" } + let(:person_index) { 3 } + + it "has correct depends_on" do + expect(page.depends_on).to eq([ + { + "not_joint_purchase?" => true, + "hholdcount" => { + "operator" => ">=", + "operand" => 3, + }, + }, + { + "joint_purchase?" => true, + "hholdcount" => { + "operator" => ">=", + "operand" => 3, + }, + }, + ]) + end + end + + context "with person 4" do + let(:page_id) { "person_4_known" } + let(:person_index) { 4 } + + it "has correct depends_on" do + expect(page.depends_on).to eq([ + { + "not_joint_purchase?" => true, + "hholdcount" => { + "operator" => ">=", + "operand" => 4, + }, + }, + { + "joint_purchase?" => true, + "hholdcount" => { + "operator" => ">=", + "operand" => 4, + }, + }, + ]) + end + end + + context "with person 5" do + let(:page_id) { "person_5_known" } + let(:person_index) { 5 } + + it "has correct depends_on" do + expect(page.depends_on).to eq([ + { + "not_joint_purchase?" => true, + "hholdcount" => { + "operator" => ">=", + "operand" => 5, + }, + }, + { + "joint_purchase?" => true, + "hholdcount" => { + "operator" => ">=", + "operand" => 5, + }, + }, + ]) + end + end + end end diff --git a/spec/models/form/sales/questions/number_of_others_in_property_spec.rb b/spec/models/form/sales/questions/number_of_others_in_property_spec.rb index 7bf19dbe3..6d926c9c4 100644 --- a/spec/models/form/sales/questions/number_of_others_in_property_spec.rb +++ b/spec/models/form/sales/questions/number_of_others_in_property_spec.rb @@ -5,30 +5,45 @@ RSpec.describe Form::Sales::Questions::NumberOfOthersInProperty, type: :model do let(:question_id) { nil } let(:question_definition) { nil } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } let(:joint_purchase) { true } - it "has correct page" do - expect(question.page).to be(page) - end + context "with 2023 form" do + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false))) } - it "has the correct id" do - expect(question.id).to eq("hholdcount") - end + it "has correct page" do + expect(question.page).to be(page) + end - it "has the correct type" do - expect(question.type).to eq("numeric") - end + it "has the correct id" do + expect(question.id).to eq("hholdcount") + end - it "is not marked as derived" do - expect(question.derived?(nil)).to be false - end + it "has the correct type" do + expect(question.type).to eq("numeric") + end - it "has the correct min" do - expect(question.min).to be 0 + it "is not marked as derived" do + expect(question.derived?(nil)).to be false + end + + it "has the correct min" do + expect(question.min).to be 0 + end + + it "has the correct max" do + expect(question.max).to be 15 + end end - it "has the correct max" do - expect(question.max).to be 15 + context "with 2026 form" do + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2026, 4, 1), start_year_2026_or_later?: true))) } + + it "has the correct min" do + expect(question.min).to be 1 + end + + it "has the correct max" do + expect(question.max).to be 15 + end end end