diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 0a2d1ad65..467b049df 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -54,7 +54,7 @@ class FormController < ApplicationController if @page.routed_to?(@log, current_user) render "form/page" else - redirect_to lettings_log_path(@log) + redirect_to @log.lettings? ? lettings_log_path(@log) : sales_log_path(@log) end else render_not_found diff --git a/app/models/form/sales/pages/housing_benefits.rb b/app/models/form/sales/pages/housing_benefits.rb index 5de83cbfd..670673bd8 100644 --- a/app/models/form/sales/pages/housing_benefits.rb +++ b/app/models/form/sales/pages/housing_benefits.rb @@ -1,12 +1,13 @@ class Form::Sales::Pages::HousingBenefits < ::Form::Page - def initialize(id, hsh, subsection) - super - @id = "housing_benefits" + def initialize(id, hsh, subsection, joint_purchase:) + super(id, hsh, subsection) + @joint_purchase = joint_purchase + @depends_on = [{ "jointpur" => @joint_purchase ? 1 : 2 }] end def questions @questions ||= [ - Form::Sales::Questions::HousingBenefits.new(nil, nil, self), + Form::Sales::Questions::HousingBenefits.new(nil, nil, self, joint_purchase: @joint_purchase), ] end end diff --git a/app/models/form/sales/questions/housing_benefits.rb b/app/models/form/sales/questions/housing_benefits.rb index db3e14c88..a4af620e6 100644 --- a/app/models/form/sales/questions/housing_benefits.rb +++ b/app/models/form/sales/questions/housing_benefits.rb @@ -1,9 +1,9 @@ class Form::Sales::Questions::HousingBenefits < ::Form::Question - def initialize(id, hsh, page) - super + def initialize(id, hsh, page, joint_purchase:) + super(id, hsh, page) @id = "hb" @check_answer_label = "Housing-related benefits buyer received before buying this property" - @header = "Was the buyer receiving any of these housing-related benefits immediately before buying this property?" + @header = "#{joint_purchase ? 'Were the buyers' : 'Was the buyer'} receiving any of these housing-related benefits immediately before buying this property?" @type = "radio" @answer_options = ANSWER_OPTIONS end 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 7642e84bd..9ff584d47 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -18,7 +18,8 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection Form::Sales::Pages::Buyer2IncomeValueCheck.new("buyer_2_income_value_check", nil, self), Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self), Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2), - Form::Sales::Pages::HousingBenefits.new(nil, nil, self), + 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), diff --git a/spec/models/form/sales/pages/housing_benefits_spec.rb b/spec/models/form/sales/pages/housing_benefits_spec.rb index 9cf017bdc..f4a591d40 100644 --- a/spec/models/form/sales/pages/housing_benefits_spec.rb +++ b/spec/models/form/sales/pages/housing_benefits_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Pages::HousingBenefits, 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:) } - let(:page_id) { nil } + let(:page_id) { "provided_id" } let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection) } + let(:joint_purchase) { false } it "has correct subsection" do expect(page.subsection).to eq(subsection) @@ -16,7 +17,7 @@ RSpec.describe Form::Sales::Pages::HousingBenefits, type: :model do end it "has the correct id" do - expect(page.id).to eq("housing_benefits") + expect(page.id).to eq(page_id) end it "has the correct header" do @@ -27,7 +28,17 @@ RSpec.describe Form::Sales::Pages::HousingBenefits, type: :model do expect(page.description).to be_nil end - it "has correct depends_on" do - expect(page.depends_on).to be_nil + context "when joint_purchase is false" do + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "jointpur" => 2 }]) + end + end + + context "when joint_purchase is true" do + let(:joint_purchase) { true } + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "jointpur" => 1 }]) + end end end diff --git a/spec/models/form/sales/questions/housing_benefits_spec.rb b/spec/models/form/sales/questions/housing_benefits_spec.rb index 8c3ae57d3..12ae84774 100644 --- a/spec/models/form/sales/questions/housing_benefits_spec.rb +++ b/spec/models/form/sales/questions/housing_benefits_spec.rb @@ -1,11 +1,12 @@ require "rails_helper" RSpec.describe Form::Sales::Questions::HousingBenefits, 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:) } let(:question_id) { nil } let(:question_definition) { nil } let(:page) { instance_double(Form::Page) } + let(:joint_purchase) { false } it "has correct page" do expect(question.page).to eq(page) @@ -15,8 +16,18 @@ RSpec.describe Form::Sales::Questions::HousingBenefits, type: :model do expect(question.id).to eq("hb") end - it "has the correct header" do - expect(question.header).to eq("Was the buyer receiving any of these housing-related benefits immediately before buying this property?") + context "when joint purchase is false" do + it "has the correct header" do + expect(question.header).to eq("Was the buyer receiving any of these housing-related benefits immediately before buying this property?") + end + end + + context "when joint purchase is true" do + let(:joint_purchase) { true } + + it "has the correct header" do + expect(question.header).to eq("Were the buyers receiving any of these housing-related benefits immediately before buying this property?") + end end it "has the correct check_answer_label" do 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 cfc677233..6c0997fd2 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 @@ -30,7 +30,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model buyer_2_income_value_check buyer_2_mortgage buyer_2_mortgage_value_check - housing_benefits + housing_benefits_joint_purchase + housing_benefits_not_joint_purchase savings savings_value_check savings_deposit_value_check @@ -56,7 +57,8 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model buyer_2_income_value_check buyer_2_mortgage buyer_2_mortgage_value_check - housing_benefits + housing_benefits_joint_purchase + housing_benefits_not_joint_purchase savings savings_value_check savings_deposit_value_check diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index fb7bad4b2..a6b5b181a 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -54,14 +54,14 @@ RSpec.describe FormHandler do it "is able to load a current sales form" do form = form_handler.get_form("current_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(182) + expect(form.pages.count).to be_positive expect(form.name).to eq("2022_2023_sales") end it "is able to load a previous sales form" do form = form_handler.get_form("previous_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(182) + expect(form.pages.count).to be_positive expect(form.name).to eq("2021_2022_sales") end end