From 8528e73efc00a1bdfbfacf736642d4b683249bb7 Mon Sep 17 00:00:00 2001 From: oscar-richardson-softwire Date: Mon, 9 Feb 2026 12:08:01 +0000 Subject: [PATCH] Improve person_lead_partner tests --- .../pages/person_lead_partner_spec.rb | 80 +++++++++++++++++-- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/spec/models/form/lettings/pages/person_lead_partner_spec.rb b/spec/models/form/lettings/pages/person_lead_partner_spec.rb index b5ec6e7ac..63b6b0cda 100644 --- a/spec/models/form/lettings/pages/person_lead_partner_spec.rb +++ b/spec/models/form/lettings/pages/person_lead_partner_spec.rb @@ -19,10 +19,6 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do end context "with person 2" do - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[relat2]) - end - it "has the correct id" do expect(page.id).to eq("person_2_lead_partner") end @@ -30,6 +26,10 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do context "with start year < 2026", metadata: { year: 25 } do let(:person_question_count) { 4 } + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat2]) + end + it "has correct depends_on" do expect(page.depends_on).to eq( [{ "details_known_2" => 0 }], @@ -41,6 +41,10 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do let(:start_year_2026_or_later?) { true } let(:person_question_count) { 5 } + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat2]) + end + it "has correct depends_on" do expect(page.depends_on).to eq( [ @@ -61,10 +65,6 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do context "with person 3" do let(:person_index) { 3 } - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[relat3]) - end - it "has the correct id" do expect(page.id).to eq("person_3_lead_partner") end @@ -72,6 +72,10 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do context "with start year < 2026", metadata: { year: 25 } do let(:person_question_count) { 4 } + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat3]) + end + it "has correct depends_on" do expect(page.depends_on).to eq( [{ "details_known_3" => 0 }], @@ -83,6 +87,10 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do let(:start_year_2026_or_later?) { true } let(:person_question_count) { 5 } + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat3]) + end + it "has correct depends_on" do expect(page.depends_on).to eq( [ @@ -104,4 +112,60 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do end end end + + context "with person 4" do + let(:person_index) { 4 } + + it "has the correct id" do + expect(page.id).to eq("person_4_lead_partner") + end + + context "with start year < 2026", metadata: { year: 25 } do + before do + allow(form).to receive(:start_year_2026_or_later?).and_return(false) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat4]) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "details_known_4" => 0 }], + ) + end + end + + context "with start year >= 2026", metadata: { year: 26 } do + before do + allow(form).to receive(:start_year_2026_or_later?).and_return(true) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat4]) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { + "details_known_4" => 0, + "age4" => { + "operator" => ">=", + "operand" => 16, + }, + "relat2" => { "operator" => "!=", "operand" => "P" }, + "relat3" => { "operator" => "!=", "operand" => "P" }, + }, + { + "details_known_4" => 0, + "age4" => nil, + "relat2" => { "operator" => "!=", "operand" => "P" }, + "relat3" => { "operator" => "!=", "operand" => "P" }, + }, + ], + ) + end + end + end end