From f1d03799d5819784b370fb4461e113522ac2d28c Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 28 Feb 2024 13:12:17 +0000 Subject: [PATCH] Pluralise buyer in savings --- app/models/form/sales/pages/savings.rb | 18 ++++++++++++----- .../form/sales/pages/savings_value_check.rb | 20 +++++++++++-------- app/models/form/sales/questions/savings.rb | 6 +++--- app/models/form/sales/questions/savings_nk.rb | 8 ++++---- .../income_benefits_and_savings.rb | 9 ++++++--- spec/models/form/sales/pages/savings_spec.rb | 14 ++++++++++--- .../sales/pages/savings_value_check_spec.rb | 18 +++++++++++++---- .../form/sales/questions/savings_nk_spec.rb | 2 +- .../form/sales/questions/savings_spec.rb | 2 +- .../income_benefits_and_savings_spec.rb | 6 ++++++ 10 files changed, 71 insertions(+), 32 deletions(-) diff --git a/app/models/form/sales/pages/savings.rb b/app/models/form/sales/pages/savings.rb index 969ff414c..462a1f82c 100644 --- a/app/models/form/sales/pages/savings.rb +++ b/app/models/form/sales/pages/savings.rb @@ -1,13 +1,21 @@ class Form::Sales::Pages::Savings < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "savings" + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) + @joint_purchase = joint_purchase end def questions @questions ||= [ - Form::Sales::Questions::SavingsNk.new(nil, nil, self), - Form::Sales::Questions::Savings.new(nil, nil, self), + Form::Sales::Questions::SavingsNk.new(nil, nil, self, joint_purchase: @joint_purchase), + Form::Sales::Questions::Savings.new(nil, nil, self, joint_purchase: @joint_purchase), ] end + + def depends_on + if @joint_purchase + [{ "joint_purchase?" => true }] + else + [{ "not_joint_purchase?" => true }] + end + end end diff --git a/app/models/form/sales/pages/savings_value_check.rb b/app/models/form/sales/pages/savings_value_check.rb index 6a45a1929..0febd1edb 100644 --- a/app/models/form/sales/pages/savings_value_check.rb +++ b/app/models/form/sales/pages/savings_value_check.rb @@ -1,13 +1,8 @@ class Form::Sales::Pages::SavingsValueCheck < ::Form::Page - def initialize(id, hsh, subsection) - super - @depends_on = [ - { - "savings_over_soft_max?" => true, - }, - ] + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) @title_text = { - "translation" => "soft_validations.savings.title_text", + "translation" => "soft_validations.savings.title_text.#{joint_purchase ? 'two' : 'one'}", "arguments" => [ { "key" => "field_formatted_as_currency", @@ -20,6 +15,7 @@ class Form::Sales::Pages::SavingsValueCheck < ::Form::Page "translation" => "soft_validations.savings.hint_text", "arguments" => [], } + @joint_purchase = joint_purchase end def questions @@ -31,4 +27,12 @@ class Form::Sales::Pages::SavingsValueCheck < ::Form::Page def interruption_screen_question_ids %w[savings] end + + def depends_on + if @joint_purchase + [{ "joint_purchase?" => true, "savings_over_soft_max?" => true }] + else + [{ "not_joint_purchase?" => true, "savings_over_soft_max?" => true }] + end + end end diff --git a/app/models/form/sales/questions/savings.rb b/app/models/form/sales/questions/savings.rb index 6c01ed2fd..b2478e999 100644 --- a/app/models/form/sales/questions/savings.rb +++ b/app/models/form/sales/questions/savings.rb @@ -1,8 +1,8 @@ class Form::Sales::Questions::Savings < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "savings" - @check_answer_label = "Buyer’s total savings before any deposit paid" + @check_answer_label = "#{joint_purchase ? 'Buyers’' : 'Buyer’s'} total savings before any deposit paid" @header = "Enter their total savings to the nearest £10" @type = "numeric" @width = 5 diff --git a/app/models/form/sales/questions/savings_nk.rb b/app/models/form/sales/questions/savings_nk.rb index 515f0a544..e124215af 100644 --- a/app/models/form/sales/questions/savings_nk.rb +++ b/app/models/form/sales/questions/savings_nk.rb @@ -1,9 +1,9 @@ class Form::Sales::Questions::SavingsNk < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "savingsnk" - @check_answer_label = "Buyer’s total savings known?" - @header = "Do you know how much the buyer had in savings before they paid any deposit for the property?" + @check_answer_label = "#{joint_purchase ? 'Buyers’' : 'Buyer’s'} total savings known?" + @header = "Do you know how much the #{joint_purchase ? 'buyers' : 'buyer'} had in savings before they paid any deposit for the property?" @type = "radio" @answer_options = ANSWER_OPTIONS @conditional_for = { diff --git a/app/models/form/sales/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb index c4d4fecaa..19b6e7e03 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -24,9 +24,12 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2), Form::Sales::Pages::HousingBenefits.new("housing_benefits_joint_purchase", nil, self, joint_purchase: true), Form::Sales::Pages::HousingBenefits.new("housing_benefits_not_joint_purchase", nil, self, joint_purchase: false), - Form::Sales::Pages::Savings.new(nil, nil, self), - Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self), - Form::Sales::Pages::DepositValueCheck.new("savings_deposit_value_check", nil, self), + Form::Sales::Pages::Savings.new("savings_joint_purchase", nil, self, joint_purchase: true), + Form::Sales::Pages::Savings.new("savings", nil, self, joint_purchase: false), + Form::Sales::Pages::SavingsValueCheck.new("savings_joint_purchase_value_check", nil, self, joint_purchase: true), + Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self, joint_purchase: false), + Form::Sales::Pages::DepositValueCheck.new("savings_deposit_joint_purchase_value_check", nil, self, joint_purchase: true), + Form::Sales::Pages::DepositValueCheck.new("savings_deposit_value_check", nil, self, joint_purchase: false), Form::Sales::Pages::PreviousOwnership.new("previous_ownership_joint_purchase", nil, self, joint_purchase: true), Form::Sales::Pages::PreviousOwnership.new("previous_ownership_not_joint_purchase", nil, self, joint_purchase: false), previous_shared_page, diff --git a/spec/models/form/sales/pages/savings_spec.rb b/spec/models/form/sales/pages/savings_spec.rb index aaf3f86c4..04c7279f9 100644 --- a/spec/models/form/sales/pages/savings_spec.rb +++ b/spec/models/form/sales/pages/savings_spec.rb @@ -1,9 +1,9 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::Savings, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) } - let(:page_id) { nil } + let(:page_id) { "savings" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } @@ -28,6 +28,14 @@ RSpec.describe Form::Sales::Pages::Savings, type: :model do end it "has correct depends_on" do - expect(page.depends_on).to be_nil + expect(page.depends_on).to eq([{ "not_joint_purchase?" => true }]) + end + + context "with joint purchase" do + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) } + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "joint_purchase?" => true }]) + end end end diff --git a/spec/models/form/sales/pages/savings_value_check_spec.rb b/spec/models/form/sales/pages/savings_value_check_spec.rb index cfff9c74d..cd9b5ef34 100644 --- a/spec/models/form/sales/pages/savings_value_check_spec.rb +++ b/spec/models/form/sales/pages/savings_value_check_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::SavingsValueCheck, type: :model do - subject(:page) { described_class.new(page_id, page_definition, subsection) } + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: false) } let(:page_id) { "savings_value_check" } let(:page_definition) { nil } @@ -25,9 +25,8 @@ RSpec.describe Form::Sales::Pages::SavingsValueCheck, type: :model do it "has correct depends_on" do expect(page.depends_on).to eq([ - { - "savings_over_soft_max?" => true, - }, + { "not_joint_purchase?" => true, + "savings_over_soft_max?" => true }, ]) end @@ -38,4 +37,15 @@ RSpec.describe Form::Sales::Pages::SavingsValueCheck, type: :model do it "has the correct interruption_screen_question_ids" do expect(page.interruption_screen_question_ids).to eq(%w[savings]) end + + context "with joint purchase" do + subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase: true) } + + it "has correct depends_on" do + expect(page.depends_on).to eq([ + { "joint_purchase?" => true, + "savings_over_soft_max?" => true }, + ]) + end + end end diff --git a/spec/models/form/sales/questions/savings_nk_spec.rb b/spec/models/form/sales/questions/savings_nk_spec.rb index 519bdd8d4..25525e861 100644 --- a/spec/models/form/sales/questions/savings_nk_spec.rb +++ b/spec/models/form/sales/questions/savings_nk_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::SavingsNk, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: false) } let(:question_id) { nil } let(:question_definition) { nil } diff --git a/spec/models/form/sales/questions/savings_spec.rb b/spec/models/form/sales/questions/savings_spec.rb index 8e9c4daa4..d416c1e73 100644 --- a/spec/models/form/sales/questions/savings_spec.rb +++ b/spec/models/form/sales/questions/savings_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::Savings, type: :model do - subject(:question) { described_class.new(question_id, question_definition, page) } + subject(:question) { described_class.new(question_id, question_definition, page, joint_purchase: false) } let(:question_id) { nil } let(:question_definition) { nil } diff --git a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb index 07464348a..22a84f2a9 100644 --- a/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb +++ b/spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb @@ -36,8 +36,11 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model buyer_2_mortgage_value_check housing_benefits_joint_purchase housing_benefits_not_joint_purchase + savings_joint_purchase savings + savings_joint_purchase_value_check savings_value_check + savings_deposit_joint_purchase_value_check savings_deposit_value_check previous_ownership_joint_purchase previous_ownership_not_joint_purchase @@ -68,8 +71,11 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model buyer_2_mortgage_value_check housing_benefits_joint_purchase housing_benefits_not_joint_purchase + savings_joint_purchase savings + savings_joint_purchase_value_check savings_value_check + savings_deposit_joint_purchase_value_check savings_deposit_value_check previous_ownership_joint_purchase previous_ownership_not_joint_purchase