From 9a4f2bc52d42d9915f50e1ba2e9d0ae3c40e6181 Mon Sep 17 00:00:00 2001 From: Rachael Booth Date: Wed, 9 Oct 2024 13:50:16 +0100 Subject: [PATCH] Add tests where there is logic on page/question to decide copy key --- .../form/sales/pages/buyer_interview_spec.rb | 16 ++++++++++++++ .../form/sales/pages/privacy_notice_spec.rb | 22 ++++++++++++------- .../sales/questions/buyer_interview_spec.rb | 16 ++++++++++++++ .../sales/questions/privacy_notice_spec.rb | 16 ++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/spec/models/form/sales/pages/buyer_interview_spec.rb b/spec/models/form/sales/pages/buyer_interview_spec.rb index 9065c3e57..ce72974e9 100644 --- a/spec/models/form/sales/pages/buyer_interview_spec.rb +++ b/spec/models/form/sales/pages/buyer_interview_spec.rb @@ -22,4 +22,20 @@ RSpec.describe Form::Sales::Pages::BuyerInterview, type: :model do it "has the correct description" do expect(page.description).to be_nil end + + context "when there are joint buyers" do + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) } + + it "has the expected copy_key" do + expect(page.copy_key).to eq("sales.setup.noint.joint_purchase") + end + end + + context "when there is a single buyer" do + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) } + + it "has the expected copy_key" do + expect(page.copy_key).to eq("sales.setup.noint.not_joint_purchase") + end + end end diff --git a/spec/models/form/sales/pages/privacy_notice_spec.rb b/spec/models/form/sales/pages/privacy_notice_spec.rb index 774b7f3b9..1d146f0af 100644 --- a/spec/models/form/sales/pages/privacy_notice_spec.rb +++ b/spec/models/form/sales/pages/privacy_notice_spec.rb @@ -29,21 +29,27 @@ RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to eq([{ "not_joint_purchase?" => true }, { "jointpur" => nil }]) - end - - context "with joint purchase" do + context "when there are joint buyers" do subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) } - let(:page_id) { "privacy_notice_joint_purchase" } + it "has the expected copy_key" do + expect(page.copy_key).to eq("sales.setup.privacynotice.joint_purchase") + end it "has correct depends_on" do expect(page.depends_on).to eq([{ "joint_purchase?" => true }]) end + end + + context "when there is a single buyer" do + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) } + + it "has the expected copy_key" do + expect(page.copy_key).to eq("sales.setup.privacynotice.not_joint_purchase") + end - it "has the correct id" do - expect(page.id).to eq("privacy_notice_joint_purchase") + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "not_joint_purchase?" => true }, { "jointpur" => nil }]) end end end diff --git a/spec/models/form/sales/questions/buyer_interview_spec.rb b/spec/models/form/sales/questions/buyer_interview_spec.rb index df5dcd0be..3370a84f5 100644 --- a/spec/models/form/sales/questions/buyer_interview_spec.rb +++ b/spec/models/form/sales/questions/buyer_interview_spec.rb @@ -29,4 +29,20 @@ RSpec.describe Form::Sales::Questions::BuyerInterview, type: :model do "1" => { "value" => "No" }, }) end + + context "when there are joint buyers" do + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) } + + it "has the expected copy_key" do + expect(question.copy_key).to eq("sales.setup.noint.joint_purchase") + end + end + + context "when there is a single buyer" do + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: false) } + + it "has the expected copy_key" do + expect(question.copy_key).to eq("sales.setup.noint.not_joint_purchase") + end + end end diff --git a/spec/models/form/sales/questions/privacy_notice_spec.rb b/spec/models/form/sales/questions/privacy_notice_spec.rb index b862c9ff0..11589049d 100644 --- a/spec/models/form/sales/questions/privacy_notice_spec.rb +++ b/spec/models/form/sales/questions/privacy_notice_spec.rb @@ -31,6 +31,22 @@ RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do expect(question.derived?(nil)).to be false end + context "when there are joint buyers" do + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: true) } + + it "has the expected copy_key" do + expect(question.copy_key).to eq("sales.setup.privacynotice.joint_purchase") + end + end + + context "when there is a single buyer" do + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: false) } + + it "has the expected copy_key" do + expect(question.copy_key).to eq("sales.setup.privacynotice.not_joint_purchase") + end + end + context "when the form year is before 2024" do before do allow(form).to receive(:start_year_after_2024?).and_return(false)