From 154f4d9538f2b77dc2c1159ad7ae9b2b66a1f822 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:28:44 +0000 Subject: [PATCH] CLDC-3721: Sales - Move Q78 (Is this a staircasing transaction?) to setup section (25/26) (#2751) --- app/models/form/sales/pages/staircase.rb | 3 +- app/models/form/sales/questions/staircase.rb | 22 +++++-- app/models/form/sales/subsections/setup.rb | 1 + .../subsections/shared_ownership_scheme.rb | 2 +- .../forms/2025/sales/sale_information.en.yml | 5 -- config/locales/forms/2025/sales/setup.en.yml | 6 ++ .../models/form/sales/pages/staircase_spec.rb | 40 +++++++++--- .../form/sales/questions/staircase_spec.rb | 64 +++++++++++++------ .../form/sales/subsections/setup_spec.rb | 1 + .../shared_ownership_scheme_spec.rb | 2 +- 10 files changed, 100 insertions(+), 46 deletions(-) diff --git a/app/models/form/sales/pages/staircase.rb b/app/models/form/sales/pages/staircase.rb index 28b0d6b38..1413abadc 100644 --- a/app/models/form/sales/pages/staircase.rb +++ b/app/models/form/sales/pages/staircase.rb @@ -2,7 +2,8 @@ class Form::Sales::Pages::Staircase < ::Form::Page def initialize(id, hsh, subsection) super @id = "staircasing" - @copy_key = "sales.sale_information.staircasing" + @depends_on = [{ "ownershipsch" => 1 }] + @copy_key = "sales.#{subsection.id}.staircasing" end def questions diff --git a/app/models/form/sales/questions/staircase.rb b/app/models/form/sales/questions/staircase.rb index 9fc969735..6c98397ff 100644 --- a/app/models/form/sales/questions/staircase.rb +++ b/app/models/form/sales/questions/staircase.rb @@ -2,17 +2,25 @@ class Form::Sales::Questions::Staircase < ::Form::Question def initialize(id, hsh, page) super @id = "staircase" - @copy_key = "sales.sale_information.staircasing" + @copy_key = "sales.#{page.subsection.id}.staircasing" @type = "radio" - @answer_options = ANSWER_OPTIONS @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] end - ANSWER_OPTIONS = { - "1" => { "value" => "Yes" }, - "2" => { "value" => "No" }, - "3" => { "value" => "Don’t know" }, - }.freeze + def answer_options + if form.start_year_2025_or_later? + { + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }.freeze + else + { + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + "3" => { "value" => "Don’t know" }, + }.freeze + end + end QUESTION_NUMBER_FROM_YEAR = { 2023 => 76, 2024 => 78 }.freeze end diff --git a/app/models/form/sales/subsections/setup.rb b/app/models/form/sales/subsections/setup.rb index dd078c9f2..87656505f 100644 --- a/app/models/form/sales/subsections/setup.rb +++ b/app/models/form/sales/subsections/setup.rb @@ -13,6 +13,7 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection Form::Sales::Pages::CreatedBy.new(nil, nil, self), Form::Sales::Pages::PurchaserCode.new(nil, nil, self), Form::Sales::Pages::OwnershipScheme.new(nil, nil, self), + (Form::Sales::Pages::Staircase.new(nil, nil, self) if form.start_year_2025_or_later?), Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self), Form::Sales::Pages::DiscountedOwnershipType.new(nil, nil, self), (Form::Sales::Pages::OutrightOwnershipType.new(nil, nil, self) unless form.start_year_2025_or_later?), diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 3fba8ef70..455755e31 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -10,7 +10,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection @pages ||= [ Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership_joint_purchase", nil, self, ownershipsch: 1, joint_purchase: true), Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership", nil, self, ownershipsch: 1, joint_purchase: false), - Form::Sales::Pages::Staircase.new(nil, nil, self), + (Form::Sales::Pages::Staircase.new(nil, nil, self) unless form.start_year_2025_or_later?), Form::Sales::Pages::AboutStaircase.new("about_staircasing_joint_purchase", nil, self, joint_purchase: true), Form::Sales::Pages::AboutStaircase.new("about_staircasing_not_joint_purchase", nil, self, joint_purchase: false), Form::Sales::Pages::StaircaseBoughtValueCheck.new(nil, nil, self), diff --git a/config/locales/forms/2025/sales/sale_information.en.yml b/config/locales/forms/2025/sales/sale_information.en.yml index 51270a92e..33826e58b 100644 --- a/config/locales/forms/2025/sales/sale_information.en.yml +++ b/config/locales/forms/2025/sales/sale_information.en.yml @@ -25,11 +25,6 @@ en: hint_text: "" question_text: "Did the buyer live in the property before purchasing it?" - staircasing: - page_header: "" - check_answer_label: "Staircasing transaction" - hint_text: "A staircasing transaction is when the household purchases more shares in their property, increasing the proportion they own and decreasing the proportion the housing association owns. Once the household purchases 100% of the shares, they own the property" - question_text: "Is this a staircasing transaction?" about_staircasing: page_header: "About the staircasing transaction" stairbought: diff --git a/config/locales/forms/2025/sales/setup.en.yml b/config/locales/forms/2025/sales/setup.en.yml index fcd942243..996ec5df3 100644 --- a/config/locales/forms/2025/sales/setup.en.yml +++ b/config/locales/forms/2025/sales/setup.en.yml @@ -39,6 +39,12 @@ en: hint_text: "" question_text: "Was this purchase made through an ownership scheme?" + staircasing: + page_header: "" + check_answer_label: "Staircasing transaction" + hint_text: "A staircasing transaction is when the household purchases more shares in their property, increasing the proportion they own and decreasing the proportion the housing association owns. Once the household purchases 100% of the shares, they own the property" + question_text: "Is this a staircasing transaction?" + type: shared_ownership: page_header: "Type of shared ownership sale" diff --git a/spec/models/form/sales/pages/staircase_spec.rb b/spec/models/form/sales/pages/staircase_spec.rb index 6f17e7e89..3c26181c2 100644 --- a/spec/models/form/sales/pages/staircase_spec.rb +++ b/spec/models/form/sales/pages/staircase_spec.rb @@ -7,19 +7,39 @@ RSpec.describe Form::Sales::Pages::Staircase, type: :model do let(:page_definition) { nil } let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } - it "has correct subsection" do - expect(page.subsection).to eq(subsection) - end + context "when start year is 2024" do + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)), id: "sale_information") } - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[staircase]) - end + before do + allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(false) + end + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[staircase]) + end - it "has the correct id" do - expect(page.id).to eq("staircasing") + it "has the correct id" do + expect(page.id).to eq("staircasing") + end + + it "has the correct description" do + expect(page.description).to be_nil + end end - it "has the correct description" do - expect(page.description).to be_nil + context "when start year is >= 2025" do + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)), id: "setup") } + + before do + allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(true) + end + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end end end diff --git a/spec/models/form/sales/questions/staircase_spec.rb b/spec/models/form/sales/questions/staircase_spec.rb index 7b45891da..29ba34d31 100644 --- a/spec/models/form/sales/questions/staircase_spec.rb +++ b/spec/models/form/sales/questions/staircase_spec.rb @@ -5,33 +5,55 @@ RSpec.describe Form::Sales::Questions::Staircase, 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)))) } - it "has correct page" do - expect(question.page).to eq(page) - end + context "when start year is 2024" do + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1)), id: "sale_information")) } - it "has the correct id" do - expect(question.id).to eq("staircase") - end + before do + allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(false) + end - it "has the correct type" do - expect(question.type).to eq("radio") - end + it "has correct page" do + expect(question.page).to eq(page) + end - it "is not marked as derived" do - expect(question.derived?(nil)).to be false - end + it "has the correct id" do + expect(question.id).to eq("staircase") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end - it "has the correct answer_options" do - expect(question.answer_options).to eq({ - "1" => { "value" => "Yes" }, - "2" => { "value" => "No" }, - "3" => { "value" => "Don’t know" }, - }) + it "is not marked as derived" do + expect(question.derived?(nil)).to be false + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + "3" => { "value" => "Don’t know" }, + }) + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq(nil) + end end - it "has correct conditional for" do - expect(question.conditional_for).to eq(nil) + context "when start year is 2025" do + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1)), id: "setup")) } + + before do + allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(true) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No" }, + }) + end end end diff --git a/spec/models/form/sales/subsections/setup_spec.rb b/spec/models/form/sales/subsections/setup_spec.rb index 7ed5546dd..1731ab256 100644 --- a/spec/models/form/sales/subsections/setup_spec.rb +++ b/spec/models/form/sales/subsections/setup_spec.rb @@ -93,6 +93,7 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do assigned_to purchaser_code ownership_scheme + staircasing shared_ownership_type discounted_ownership_type buyer_company diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb index 8c5674d0b..4c546d58c 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do let(:section) { instance_double(Form::Sales::Sections::SaleInformation) } before do - allow(section).to receive(:form).and_return(instance_double(Form, start_year_2024_or_later?: false, start_date: Time.zone.local(2023, 4, 1))) + allow(section).to receive(:form).and_return(instance_double(Form, start_year_2024_or_later?: false, start_year_2025_or_later?: false, start_date: Time.zone.local(2023, 4, 1))) end it "has correct section" do