Browse Source

Merge branch 'main' into CLDC-3698-update-household-needs-naming

pull/2772/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
98c7f4ddd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      app/models/form/sales/pages/buyer_live.rb
  2. 20
      app/models/form/sales/pages/joint_purchase.rb
  3. 3
      app/models/form/sales/pages/staircase.rb
  4. 22
      app/models/form/sales/questions/staircase.rb
  5. 5
      app/models/form/sales/subsections/setup.rb
  6. 2
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  7. 5
      config/locales/forms/2025/sales/sale_information.en.yml
  8. 18
      config/locales/forms/2025/sales/setup.en.yml
  9. 58
      spec/models/form/sales/pages/buyer_live_spec.rb
  10. 60
      spec/models/form/sales/pages/joint_purchase_spec.rb
  11. 40
      spec/models/form/sales/pages/staircase_spec.rb
  12. 64
      spec/models/form/sales/questions/staircase_spec.rb
  13. 3
      spec/models/form/sales/subsections/setup_spec.rb
  14. 2
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

7
app/models/form/sales/pages/buyer_live.rb

@ -2,9 +2,10 @@ class Form::Sales::Pages::BuyerLive < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "buyer_live" @id = "buyer_live"
@depends_on = [{ end
"companybuy" => 2,
}] def depends_on
[{ "companybuy" => 2 }] unless form.start_year_2025_or_later?
end end
def questions def questions

20
app/models/form/sales/pages/joint_purchase.rb

@ -2,11 +2,21 @@ class Form::Sales::Pages::JointPurchase < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "joint_purchase" @id = "joint_purchase"
@depends_on = [ end
{ "ownershipsch" => 1 },
{ "ownershipsch" => 2 }, def depends_on
{ "companybuy" => 2 }, if form.start_year_2025_or_later?
] [
{ "ownershipsch" => 1 },
{ "ownershipsch" => 2 },
]
else
[
{ "ownershipsch" => 1 },
{ "ownershipsch" => 2 },
{ "companybuy" => 2 },
]
end
end end
def questions def questions

3
app/models/form/sales/pages/staircase.rb

@ -2,7 +2,8 @@ class Form::Sales::Pages::Staircase < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@id = "staircasing" @id = "staircasing"
@copy_key = "sales.sale_information.staircasing" @depends_on = [{ "ownershipsch" => 1 }]
@copy_key = "sales.#{subsection.id}.staircasing"
end end
def questions def questions

22
app/models/form/sales/questions/staircase.rb

@ -2,17 +2,25 @@ class Form::Sales::Questions::Staircase < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "staircase" @id = "staircase"
@copy_key = "sales.sale_information.staircasing" @copy_key = "sales.#{page.subsection.id}.staircasing"
@type = "radio" @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] @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max]
end end
ANSWER_OPTIONS = { def answer_options
"1" => { "value" => "Yes" }, if form.start_year_2025_or_later?
"2" => { "value" => "No" }, {
"3" => { "value" => "Don’t know" }, "1" => { "value" => "Yes" },
}.freeze "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 QUESTION_NUMBER_FROM_YEAR = { 2023 => 76, 2024 => 78 }.freeze
end end

5
app/models/form/sales/subsections/setup.rb

@ -13,11 +13,12 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection
Form::Sales::Pages::CreatedBy.new(nil, nil, self), Form::Sales::Pages::CreatedBy.new(nil, nil, self),
Form::Sales::Pages::PurchaserCode.new(nil, nil, self), Form::Sales::Pages::PurchaserCode.new(nil, nil, self),
Form::Sales::Pages::OwnershipScheme.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::SharedOwnershipType.new(nil, nil, self),
Form::Sales::Pages::DiscountedOwnershipType.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?), (Form::Sales::Pages::OutrightOwnershipType.new(nil, nil, self) unless form.start_year_2025_or_later?),
Form::Sales::Pages::BuyerCompany.new(nil, nil, self), (Form::Sales::Pages::BuyerCompany.new(nil, nil, self) unless form.start_year_2025_or_later?),
Form::Sales::Pages::BuyerLive.new(nil, nil, self), (Form::Sales::Pages::BuyerLive.new(nil, nil, self) unless form.start_year_2025_or_later?),
Form::Sales::Pages::JointPurchase.new(nil, nil, self), Form::Sales::Pages::JointPurchase.new(nil, nil, self),
Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self), Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self),
(Form::Sales::Pages::BuyerInterview.new("buyer_interview_joint_purchase", nil, self, joint_purchase: true) if form.start_year_2024_or_later?), (Form::Sales::Pages::BuyerInterview.new("buyer_interview_joint_purchase", nil, self, joint_purchase: true) if form.start_year_2024_or_later?),

2
app/models/form/sales/subsections/shared_ownership_scheme.rb

@ -10,7 +10,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
@pages ||= [ @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_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::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_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::AboutStaircase.new("about_staircasing_not_joint_purchase", nil, self, joint_purchase: false),
Form::Sales::Pages::StaircaseBoughtValueCheck.new(nil, nil, self), Form::Sales::Pages::StaircaseBoughtValueCheck.new(nil, nil, self),

5
config/locales/forms/2025/sales/sale_information.en.yml

@ -25,11 +25,6 @@ en:
hint_text: "" hint_text: ""
question_text: "Did the buyer live in the property before purchasing it?" 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: about_staircasing:
page_header: "About the staircasing transaction" page_header: "About the staircasing transaction"
stairbought: stairbought:

18
config/locales/forms/2025/sales/setup.en.yml

@ -39,6 +39,12 @@ en:
hint_text: "" hint_text: ""
question_text: "Was this purchase made through an ownership scheme?" 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: type:
shared_ownership: shared_ownership:
page_header: "Type of shared ownership sale" page_header: "Type of shared ownership sale"
@ -51,18 +57,6 @@ en:
hint_text: "" hint_text: ""
question_text: "What is the type of discounted ownership sale?" question_text: "What is the type of discounted ownership sale?"
companybuy:
page_header: ""
check_answer_label: "Company buyer"
hint_text: ""
question_text: "Is the buyer a company?"
buylivein:
page_header: ""
check_answer_label: "Buyers living in property"
hint_text: ""
question_text: "Will any buyers live in the property?"
jointpur: jointpur:
page_header: "" page_header: ""
check_answer_label: "Joint purchase" check_answer_label: "Joint purchase"

58
spec/models/form/sales/pages/buyer_live_spec.rb

@ -8,32 +8,50 @@ RSpec.describe Form::Sales::Pages::BuyerLive, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form, start_date: current_collection_start_date) }
before do context "when start year is 2024" do
allow(form).to receive(:start_year_2024_or_later?).and_return(true) let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
allow(subsection).to receive(:form).and_return(form)
end
it "has correct subsection" do before do
expect(page.subsection).to eq(subsection) allow(form).to receive(:start_year_2024_or_later?).and_return(true)
end allow(form).to receive(:start_year_2025_or_later?).and_return(false)
allow(subsection).to receive(:form).and_return(form)
end
it "has correct questions" do it "has correct subsection" do
expect(page.questions.map(&:id)).to eq(%w[buylivein]) expect(page.subsection).to eq(subsection)
end end
it "has the correct id" do it "has correct questions" do
expect(page.id).to eq("buyer_live") expect(page.questions.map(&:id)).to eq(%w[buylivein])
end end
it "has the correct description" do it "has the correct id" do
expect(page.description).to be_nil expect(page.id).to eq("buyer_live")
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{
"companybuy" => 2,
}])
end
end end
it "has correct depends_on" do context "when start year is 2025" do
expect(page.depends_on).to eq([{ let(:form) { instance_double(Form, start_date: Time.zone.local(2025, 4, 1)) }
"companybuy" => 2,
}]) before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
allow(subsection).to receive(:form).and_return(form)
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end end
end end

60
spec/models/form/sales/pages/joint_purchase_spec.rb

@ -5,29 +5,53 @@ RSpec.describe Form::Sales::Pages::JointPurchase, type: :model do
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } 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 context "when start year is 2024" do
expect(page.subsection).to eq(subsection) let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1))) }
end
it "has correct questions" do before do
expect(page.questions.map(&:id)).to eq(%w[jointpur]) allow(subsection.form).to receive(:start_year_2024_or_later?).and_return(true)
end allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(false)
end
it "has the correct id" do it "has correct subsection" do
expect(page.id).to eq("joint_purchase") expect(page.subsection).to eq(subsection)
end end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[jointpur])
end
it "has the correct description" do it "has the correct id" do
expect(page.description).to be_nil expect(page.id).to eq("joint_purchase")
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "ownershipsch" => 1 },
{ "ownershipsch" => 2 },
{ "companybuy" => 2 },
])
end
end end
it "has correct depends_on" do context "when start year is 2025" do
expect(page.depends_on).to eq([ let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) }
{ "ownershipsch" => 1 },
{ "ownershipsch" => 2 }, before do
{ "companybuy" => 2 }, allow(subsection.form).to receive(:start_year_2024_or_later?).and_return(true)
]) allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(true)
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "ownershipsch" => 1 },
{ "ownershipsch" => 2 },
])
end
end end
end end

40
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(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) } let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1))) }
it "has correct subsection" do context "when start year is 2024" do
expect(page.subsection).to eq(subsection) let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)), id: "sale_information") }
end
it "has correct questions" do before do
expect(page.questions.map(&:id)).to eq(%w[staircase]) allow(subsection.form).to receive(:start_year_2025_or_later?).and_return(false)
end 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 it "has the correct id" do
expect(page.id).to eq("staircasing") expect(page.id).to eq("staircasing")
end
it "has the correct description" do
expect(page.description).to be_nil
end
end end
it "has the correct description" do context "when start year is >= 2025" do
expect(page.description).to be_nil 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
end end

64
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_id) { nil }
let(:question_definition) { 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 context "when start year is 2024" do
expect(question.page).to eq(page) 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")) }
end
it "has the correct id" do before do
expect(question.id).to eq("staircase") allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(false)
end end
it "has the correct type" do it "has correct page" do
expect(question.type).to eq("radio") expect(question.page).to eq(page)
end end
it "is not marked as derived" do it "has the correct id" do
expect(question.derived?(nil)).to be false expect(question.id).to eq("staircase")
end end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "has the correct answer_options" do it "is not marked as derived" do
expect(question.answer_options).to eq({ expect(question.derived?(nil)).to be false
"1" => { "value" => "Yes" }, end
"2" => { "value" => "No" },
"3" => { "value" => "Don’t know" }, 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 end
it "has correct conditional for" do context "when start year is 2025" do
expect(question.conditional_for).to eq(nil) 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
end end

3
spec/models/form/sales/subsections/setup_spec.rb

@ -93,10 +93,9 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do
assigned_to assigned_to
purchaser_code purchaser_code
ownership_scheme ownership_scheme
staircasing
shared_ownership_type shared_ownership_type
discounted_ownership_type discounted_ownership_type
buyer_company
buyer_live
joint_purchase joint_purchase
number_joint_buyers number_joint_buyers
buyer_interview_joint_purchase buyer_interview_joint_purchase

2
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) } let(:section) { instance_double(Form::Sales::Sections::SaleInformation) }
before do 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 end
it "has correct section" do it "has correct section" do

Loading…
Cancel
Save